0

i am trying to change the color of the cell using the following code, however it displays all the cell's as white font instead of the gold rgb color code i have.

if (row == 0)

    cell.detailTextLabel.text=@"An blah blah";
    cell.textLabel.textColor = [UIColor colorWithRed:139 green:136 blue:120 alpha:1];
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
Alex Stelea
  • 1,219
  • 2
  • 18
  • 29

3 Answers3

4

You're setting it on the wrong label, this should work:

cell.detailTextLabel.text=@"An blah blah";
cell.detailTextLabel.textColor = [UIColor colorWithRed:139/255.0f green:136/255.0f blue:120/255.0f alpha:1];
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
  • thanks i had the correct labels in my app, i just rewrote them wrong here sorry but thanks for the division by 255 tip – Alex Stelea Nov 15 '10 at 19:24
1

The RGB parameters are in the range 0 to 1.
Divide your 0-255 values by 255.

if (row == 0)
    cell.detailTextLabel.text=@"An blah blah";
    cell.textLabel.textColor = [UIColor colorWithRed:139/255.0f green:136/255.0f blue:120/255.0f alpha:1];

Also, maybe you meant detailTextLabel.textColor instead of textLabel.textColor.

0

I'm not sure you did if to the sake of the example but you should use

if (indexPath.row == 0){
   cell.detailTextLabel.text=@"detailed text";  
   cell.textLabel.textColor = [UIColor colorWithRed:139/255.0f green:136/255.0f blue:120/255.0f alpha:1]; 
   return;
}
endy
  • 3,872
  • 5
  • 29
  • 43