Saving a uitextfield background color

I am redoing an old objective c- app where I previously drew the text fields out on the view. I am now using the storyboard and I cannot find a way to save the background color in a plist array. It will save the text entered just fine in the plist array. I tried using NSUserdefaults no luck. I have a golf scorecard and I am looping through the textfields and comparing the score number to the par number, thus adding a different color background to the textfield: depending on the score inputed in the textfield. I could just loop back through them again when view is loaded, but was just wanting a way to save the state in a simple plist or NSUserdefaults. Looks like I might have to just make a custom textfield class. Any suggestions? Maybe need to think the whole way of laying out the textfields. I have them tagged now to locate their position on the view. I tried saving the UIcolor under the String array but I get a nstagged error when trying to add to textfield.....

Thanks

Accepted Reply

Here you go. Unfortunately you will need to convert to Swift if you are using that language. It is line-for-line convertable.


(EDIT - If you create the UITextFields programmatically then you can add them to the dictionary when they are created. Otherwise you need to type in the 72 UITextField pointers into the dictionary.)



// colors for the sore. par is index 3...
    NSArray *theColors=[NSArray arrayWithObjects:
            [UIColor colorWithRed:252.0/255.0 green:194.0/255.0 blue:0 alpha:1.0],
            [UIColor blueColor],
            [UIColor greenColor],//birdie
            [UIColor redColor],  //par
            [UIColor purpleColor],
            [UIColor orangeColor],
            [UIColor grayColor],nil];

  // the par values for all the holes
    NSArray *parValues=[NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil]; // 18 holes
    
    // a dictionary with pointers to all of the textfields
    NSDictionary *playerTextFields=[NSDictionary dictionaryWithObjectsAndKeys:
            @"Player1",[NSArray arrayWithObjects:nameOne1,nameOne2,nameOne3,nameOne4,nameOne5,nameOne6,nameOne7,nameOne8,nameOne9,nameOne10,nameOne11,nameOne12,nameOne13,nameOne14,nameOne15,nameOne16,nameOne17,nameOne18, nil]
            ,@"Player2",[NSArray
                arrayWithObjects:nameTwo1,nameTwo2,nameTwo3,nameTwo4 // continue for all nameTwo
            ,@"Player3"  // continue for player 3 textfields
            .@"Player4"  //                     
          ];
    // typical scores for each player
    NSDictionary *playerScores=[NSDictionary dictionaryWithObjectsAndKeys:
  @"Player1Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil],
  @"Player2Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil],
  @"Player3Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil],
  @"Player4Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil]];
    
    for(int hole=0;hole<=17;hole++){  //objects in the array are 0-17 not 1-18
        int par=[[parValues objectAtIndex:hole] intValue];
        for (int player=1; player<=4; player++) {
            int score=[[[playerScores objectForKey:
  [NSString stringWithFormat:@"Player%iScores",player]] 
  objectAtIndex:hole] intValue];
            if(score<par-3)score=par-3;
            if(score>par+3)score=par+3;
            UIColor *theHoleColor=[theColors objectAtIndex:(score-par+3)];
            UITextField *thePlayersHoleTextField=[[playerTextFields objectForKey:
  

Replies

I have a golf scorecard and I am looping through the textfields and comparing the score number to the par number, thus adding a different color background to the textfield


So, the color is computed for each textField ?

Why do you need to store ?

Why not set the color for each in viewWillAppear for instance ?


I tried saving the UIcolor under the String array but I get a nstagged error when trying to add to textfield.....

Which StringArray ?

Could you show the code ?


Storing color in User Defaults can be done:

h ttps://medium.com/better-programming/save-uicolor-with-userdefaults-in-swift-5-951ef1aa88e8

I decided just to compute the background colors in the view instead of storing them. But I am bad at arrarys and loops. So there has to a better way to do the code that I am using. It worksgood but it is just a lot of code to use (I think) for getting the results I need. I am taking a string value from an nsmutable array and then appling the appropriate background color as a result of the par score I know to be on every hole. I am comparing enterable numbers from a keypad from 1 to 9 against the "par" number for up to four players. I am sure this probably could be done in a for loop with arrays. However I did not know how to make a variable for the self.nameOne1.text to the next comparison of self.nameOne2.text on so on up to self.nameFour9. Any suggestions or opinions on a more logical fix would be appreciated. The code below goes from the array [playerOneFront objectAtIndex:0] all the way to [playerFourFront objectAtIndex:8], thus covering the score for the nine holes on the front side of the golf course. The self.nameOne1 thru self.nameFour9 Then I take the score on the first hole and the give it the appropriate backgound color for the par number on that hole. example if ([frontScore isEqual:@"3"])

{

self.nameOne1.backgroundColor = [UIColor systemGreenColor];

}

give a green backgroung for a birdie which is one number under "par" which is "4";


here is all the code......


-(void)getBackgrounds{


// player one


frontScore = [playerOneFront objectAtIndex:0];

if ([frontScore isEqual:@"1"])

{

self.nameOne1.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne1.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameOne1.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameOne1.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne1.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameOne1.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne1.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne1.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:1];

if ([frontScore isEqual:@"1"])

{

self.nameOne2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameOne2.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameOne2.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne2.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameOne2.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne2.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne2.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:2];

if ([frontScore isEqual:@"1"])

{

self.nameOne3.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne3.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameOne3.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameOne3.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne3.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameOne3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne3.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:3];

if ([frontScore isEqual:@"1"])

{

self.nameOne4.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne4.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameOne4.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameOne4.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne4.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameOne4.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne4.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne4.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:4];

if ([frontScore isEqual:@"1"])

{

self.nameOne5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameOne5.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameOne5.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne5.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameOne5.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne5.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne5.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:5];

if ([frontScore isEqual:@"1"])

{

self.nameOne6.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne6.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameOne6.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameOne6.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne6.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameOne6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne6.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:6];

if ([frontScore isEqual:@"1"])

{

self.nameOne7.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne7.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameOne7.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameOne7.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne7.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameOne7.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne7.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne7.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:7];

if ([frontScore isEqual:@"1"])

{

self.nameOne8.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne8.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameOne8.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameOne8.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne8.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameOne8.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne8.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne8.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerOneFront objectAtIndex:8];

if ([frontScore isEqual:@"1"])

{

self.nameOne9.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameOne9.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameOne9.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameOne9.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameOne9.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameOne9.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameOne9.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameOne9.backgroundColor = [UIColor systemGrayColor];

}

// player Two


frontScore = [playerTwoFront objectAtIndex:0];

if ([frontScore isEqual:@"1"])

{

self.nameTwo1.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo1.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameTwo1.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameTwo1.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo1.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameTwo1.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo1.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo1.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:1];

if ([frontScore isEqual:@"1"])

{

self.nameTwo2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameTwo2.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameTwo2.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo2.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameTwo2.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo2.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo2.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:2];

if ([frontScore isEqual:@"1"])

{

self.nameTwo3.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo3.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameTwo3.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameTwo3.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo3.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameTwo3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo3.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:3];

if ([frontScore isEqual:@"1"])

{

self.nameTwo4.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo4.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameTwo4.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameTwo4.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo4.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameTwo4.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo4.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo4.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:4];

if ([frontScore isEqual:@"1"])

{

self.nameTwo5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameTwo5.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameTwo5.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo5.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameTwo5.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo5.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo5.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:5];

if ([frontScore isEqual:@"1"])

{

self.nameTwo6.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo6.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameTwo6.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameTwo6.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo6.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameTwo6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo6.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:6];

if ([frontScore isEqual:@"1"])

{

self.nameTwo7.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo7.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameTwo7.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameTwo7.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo7.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameTwo7.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo7.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo7.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:7];

if ([frontScore isEqual:@"1"])

{

self.nameTwo8.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo8.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameTwo8.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameTwo8.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo8.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameTwo8.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo8.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo8.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerTwoFront objectAtIndex:8];

if ([frontScore isEqual:@"1"])

{

self.nameTwo9.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameTwo9.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameTwo9.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameTwo9.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameTwo9.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameTwo9.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameTwo9.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameTwo9.backgroundColor = [UIColor systemGrayColor];

}

// player Three


frontScore = [playerThreeFront objectAtIndex:0];

if ([frontScore isEqual:@"1"])

{

self.nameThree1.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree1.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameThree1.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameThree1.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree1.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameThree1.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree1.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree1.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:1];

if ([frontScore isEqual:@"1"])

{

self.nameThree2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameThree2.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameThree2.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree2.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameThree2.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree2.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree2.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:2];

if ([frontScore isEqual:@"1"])

{

self.nameThree3.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree3.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameThree3.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameThree3.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree3.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameThree3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree3.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:3];

if ([frontScore isEqual:@"1"])

{

self.nameThree4.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree4.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameThree4.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameThree4.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree4.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameThree4.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree4.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree4.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:4];//////////////

if ([frontScore isEqual:@"1"])

{

self.nameThree5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameThree5.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameThree5.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree5.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameThree5.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree5.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree5.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:5];

if ([frontScore isEqual:@"1"])

{

self.nameThree6.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree6.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameThree6.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameThree6.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree6.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameThree6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree6.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:6];

if ([frontScore isEqual:@"1"])

{

self.nameThree7.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree7.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameThree7.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameThree7.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree7.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameThree7.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree7.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree7.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:7];

if ([frontScore isEqual:@"1"])

{

self.nameThree8.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree8.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameThree8.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameThree8.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree8.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameThree8.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree8.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree8.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerThreeFront objectAtIndex:8];

if ([frontScore isEqual:@"1"])

{

self.nameThree9.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameThree9.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameThree9.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameThree9.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameThree9.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameThree9.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameThree9.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameThree9.backgroundColor = [UIColor systemGrayColor];

}


// player Four


frontScore = [playerFourFront objectAtIndex:0];

if ([frontScore isEqual:@"1"])

{

self.nameFour1.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour1.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameFour1.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameFour1.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour1.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameFour1.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour1.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour1.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:1];

if ([frontScore isEqual:@"1"])

{

self.nameFour2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour2.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameFour2.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameFour2.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour2.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameFour2.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour2.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour2.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:2];

if ([frontScore isEqual:@"1"])

{

self.nameFour3.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour3.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameFour3.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameFour3.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour3.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameFour3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour3.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour3.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:3];

if ([frontScore isEqual:@"1"])

{

self.nameFour4.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour4.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameFour4.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameFour4.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour4.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameFour4.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour4.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour4.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:4];//////////////

if ([frontScore isEqual:@"1"])

{

self.nameFour5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour5.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"3"])

{

self.nameFour5.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameFour5.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour5.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameFour5.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour5.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour5.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:5];

if ([frontScore isEqual:@"1"])

{

self.nameFour6.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour6.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"4"])

{

self.nameFour6.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameFour6.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour6.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual :@"7"])

{

self.nameFour6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour6.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour6.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:6];

if ([frontScore isEqual:@"1"])

{

self.nameFour7.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour7.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameFour7.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameFour7.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour7.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameFour7.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour7.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour7.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:7];

if ([frontScore isEqual:@"1"])

{

self.nameFour8.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour8.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameFour8.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameFour8.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour8.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameFour8.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour8.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour8.backgroundColor = [UIColor systemGrayColor];

}

frontScore = [playerFourFront objectAtIndex:8];

if ([frontScore isEqual:@"1"])

{

self.nameFour9.backgroundColor = [UIColor colorWithRed:252.0/255.0

green:194.0/255.0 blue:0 alpha:1.0];

}

if ([frontScore isEqual:@"2"])

{

self.nameFour9.backgroundColor = [UIColor systemBlueColor];

}

if ([frontScore isEqual:@"3"])

{

self.nameFour9.backgroundColor = [UIColor systemGreenColor];

}

if ([frontScore isEqual:@"5"])

{

self.nameFour9.backgroundColor = [UIColor systemRedColor];

}

if ([frontScore isEqual:@"6"])

{

self.nameFour9.backgroundColor = [UIColor systemPurpleColor];

}

if ([frontScore isEqual:@"7"])

{

self.nameFour9.backgroundColor = [UIColor systemOrangeColor];

}

if ([frontScore isEqual:@"8"])

{

self.nameFour9.backgroundColor = [UIColor systemGrayColor];

}

if ([frontScore isEqual:@"9"])

{

self.nameFour9.backgroundColor = [UIColor systemGrayColor];

}

}

Here you go. Unfortunately you will need to convert to Swift if you are using that language. It is line-for-line convertable.


(EDIT - If you create the UITextFields programmatically then you can add them to the dictionary when they are created. Otherwise you need to type in the 72 UITextField pointers into the dictionary.)



// colors for the sore. par is index 3...
    NSArray *theColors=[NSArray arrayWithObjects:
            [UIColor colorWithRed:252.0/255.0 green:194.0/255.0 blue:0 alpha:1.0],
            [UIColor blueColor],
            [UIColor greenColor],//birdie
            [UIColor redColor],  //par
            [UIColor purpleColor],
            [UIColor orangeColor],
            [UIColor grayColor],nil];

  // the par values for all the holes
    NSArray *parValues=[NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil]; // 18 holes
    
    // a dictionary with pointers to all of the textfields
    NSDictionary *playerTextFields=[NSDictionary dictionaryWithObjectsAndKeys:
            @"Player1",[NSArray arrayWithObjects:nameOne1,nameOne2,nameOne3,nameOne4,nameOne5,nameOne6,nameOne7,nameOne8,nameOne9,nameOne10,nameOne11,nameOne12,nameOne13,nameOne14,nameOne15,nameOne16,nameOne17,nameOne18, nil]
            ,@"Player2",[NSArray
                arrayWithObjects:nameTwo1,nameTwo2,nameTwo3,nameTwo4 // continue for all nameTwo
            ,@"Player3"  // continue for player 3 textfields
            .@"Player4"  //                     
          ];
    // typical scores for each player
    NSDictionary *playerScores=[NSDictionary dictionaryWithObjectsAndKeys:
  @"Player1Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil],
  @"Player2Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil],
  @"Player3Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil],
  @"Player4Scores",
  [NSArray arrayWithObjects:@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5",@"4",
  @"4",@"4",@"3",@"5",@"4",@"4",@"4",@"3",@"5", nil]];
    
    for(int hole=0;hole<=17;hole++){  //objects in the array are 0-17 not 1-18
        int par=[[parValues objectAtIndex:hole] intValue];
        for (int player=1; player<=4; player++) {
            int score=[[[playerScores objectForKey:
  [NSString stringWithFormat:@"Player%iScores",player]] 
  objectAtIndex:hole] intValue];
            if(score<par-3)score=par-3;
            if(score>par+3)score=par+3;
            UIColor *theHoleColor=[theColors objectAtIndex:(score-par+3)];
            UITextField *thePlayersHoleTextField=[[playerTextFields objectForKey:
  

I just noticed the following lines were missing from the code above:


          thePlayersHoleTextField.backgroundColor=theHoleColor;
     }// ends the player 1-4
}//ends the hole 0-17

Thanks, Sorry it took so long to reply back. Had a death in the family. Have not had time to try this. But will mark correct answer as I am pretty sure it will work. The problem I have now is that I have the top 9 holes in a paginated scrollview that works great on an iphone 8, but on an iphone 8 plus the bottom of the top view (hole 9) goes to far up in the first page. I am using autolayout, but I have not figured out a good way to get the scrollview to stop at hole 9 on bottom of 1st page on both devices. Any suggestions? Thanks again.

Tried the code from above. I am afraid I have a typo or bad implication of your code. Errors.. Get this .....Missing sentinel in method dispatch on a couple of the arrays, (added another nil to the end of arrarys to get it to run) and when I run the code on the second loop I get this error..Thread 1: EXE_BAD_ACCESS(code = 1,address=0x6).

Might be hung in a loop, I don't know a lot yet about debugging code from debugger. I am calling this code in a method that is ececuted from my textfield delegate that is triggered after they enter a number from my custom view of numbers that pops up onto my main view...... Thanks

Update... I think the problem is with my pointers to my textfields. I have ibactions setup for my 1-9 numbers on my custom view that I use to take the score input, then I use an instance variable "currenttextfield" to place the inputed number into my uitexfield on the view. If my logic is right......

I received this error after fixing????

-[__NSCFString setBackgroundColor:]: unrecognized selector sent to instance 0x28221cff0

2020-01-25 13:08:02.778783-0600 RiverBirch[7161:1782271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setBackgroundColor:]: unrecognized selector sent to instance 0x28221cff0'

*** First throw call stack:

(0x184376a48 0x18409dfa4 0x18427a5a8 0x18437aaf4 0x18437ca7c 0x100d5b6fc 0x100d4ae90 0x187dca920 0x187dcf430 0x187d41510 0x187d4182c 0x187d426f4 0x187d43a34 0x187d26eb8 0x18887f3d0 0x18ade27dc 0x18ade8958 0x18adf3578 0x18ad3bf1c 0x18ad65c08 0x18ad665fc 0x1842f3e68 0x1842eed54 0x1842ef320 0x1842eeadc 0x18e274328 0x1883e9ae0 0x100d8a7b0 0x184178360)

libc++abi.dylib: terminating with uncaught exception of type NSException


Printing description of theHoleColor:

(UIColor *) theHoleColor = 0x0000000100756b3f


Printing description of theColors:

<__NSArrayI 0x282775a90>(

UIExtendedSRGBColorSpace 0.988235 0.760784 0 1,

UIExtendedSRGBColorSpace 0 0 1 1,

UIExtendedSRGBColorSpace 0 1 0 1,

UIExtendedSRGBColorSpace 1 0 0 1,

UIExtendedSRGBColorSpace 0.5 0 0.5 1,

UIExtendedSRGBColorSpace 1 0.5 0 1,

UIExtendedGrayColorSpace 0.5 1

)

Finally got the code to work after implementing a few changes. Your code works great! The idea about using the par +3 or -3 was brillant! I would never thought of that.

Thanks!

Here is the code I used....


-(void)getBackgrounds{


// colors for the score. par is index 3...

NSArray *theColors=[NSArray arrayWithObjects:

[UIColor colorWithRed:252.0/255.0 green:194.0/255.0 blue:0 alpha:1.0],

[UIColor systemBlueColor],

[UIColor systemGreenColor],//birdie

[UIColor whiteColor], ///par

[UIColor systemRedColor],

[UIColor systemPurpleColor],

[UIColor systemOrangeColor],

[UIColor systemGrayColor],nil];

// the par values for all the holes

NSArray *parValues=[NSArray arrayWithObjects:@"4",@"5",@"3",@"4",@"5",@"3",@"4",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"4",@"3",@"5",@"4",@"5",@"3",@"4",@"5",@"3",@"4",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"4",@"3",@"5",@"4",@"5",@"3",@"4",@"5",@"3",@"4",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"4",@"3",@"5",@"4",@"5",@"3",@"4",@"5",@"3",@"4",@"4",@"4",@"4",@"3",@"5",@"4",@"4",@"4",@"4",@"3",@"5", nil]; //

NSMutableArray *playerTextFields=[NSMutableArray arrayWithObjects:nameOne1,nameOne2,nameOne3,nameOne4,nameOne5,nameOne6,nameOne7,nameOne8,nameOne9,nameOne1Back,nameOne2Back,nameOne3Back,nameOne4Back,nameOne5Back,nameOne6Back,nameOne7Back,nameOne8,nameOne9,nameTwo1,nameTwo2,nameTwo3,nameTwo4,nameTwo5,nameTwo6,nameTwo7,nameTwo8,nameTwo9,nameTwo1Back,nameTwo2Back,nameTwo3Back,nameTwo4Back,nameTwo5Back,nameTwo6Back,nameTwo7Back,nameTwo8Back,nameTwo9Back,nameThree1,nameThree2,nameThree3,nameThree4,nameThree5,nameThree6,nameThree7,nameThree8,nameThree9,nameThree1Back,nameThree2Back,nameThree3Back,nameThree4Back,nameThree5Back,nameThree6Back,nameThree7Back,nameThree8Back,nameThree9Back,nameFour1,nameFour2,nameFour3,nameFour4,nameFour5,nameFour6,nameFour7,nameFour8,nameFour9,nameFour1Back,nameFour2Back,nameFour3Back,nameFour4Back,nameFour5Back,nameFour6Back,nameFour7Back,nameFour8Back,nameFour9Back, nil];


for(int hole=0;hole<=71;hole++){

int par=[[parValues objectAtIndex:hole] intValue];

currenttextfield = [playerTextFields objectAtIndex:hole];

int score = currenttextfield.text.intValue;

if(score<par-3)score=par-3;

if(score>par+4)score=par+4;

UIColor *theHoleColor=[theColors objectAtIndex:(score-par+3)];

currenttextfield.backgroundColor=theHoleColor;

[playerTextFields addObject:currenttextfield];


}

}