Alex Stelea
Alex Stelea

Reputation: 1219

changing uifont color in a table cell

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];

Upvotes: 0

Views: 3613

Answers (3)

endy
endy

Reputation: 3872

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;
}

Upvotes: 0

user467105
user467105

Reputation:

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.

Upvotes: 1

Jacob Relkin
Jacob Relkin

Reputation: 163258

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];

Upvotes: 4

Related Questions