1

I am developing an application where I want to change font color of Navigation bar title and text label of Table cell.

I am using following code snip to change color

[mantraLabel setTextColor:[UIColor colorWithRed:89 green:45 blue:15 alpha:1]];

and configuring table cell as follow,

NSString *cellValue = [mantra objectAtIndex:indexPath.row];
    mantraLabel.backgroundColor=[UIColor clearColor];
    mantraLabel=[[UILabel alloc]initWithFrame:CGRectMake(60,4,200,44)];
    mantraLabel.text=cellValue;
    [mantraLabel setBaselineAdjustment:UIBaselineAdjustmentAlignCenters];
    [mantraLabel setFont:[UIFont fontWithName:@"Marathi-Vakra" size:21.0]];
    [cell addSubview:mantraLabel];
    [mantraLabel setTextColor:[UIColor colorWithRed:89 green:45 blue:15 alpha:1]];

But the Issue I am facing is that no color change is there with above statement and also one of my cell background is appearing in white color.

Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
Bhagyashree mahajan
  • 531
  • 1
  • 6
  • 14

3 Answers3

3

Correct your this line

[mantraLabel setTextColor:[UIColor colorWithRed:89 green:45 blue:15 alpha:1]];

with

[mantraLabel setTextColor:[UIColor colorWithRed:89/255.0 green:45/255.0 blue:15/255.0 alpha:1]];

Your color comes within the the range of 0.0 to 1.0. And we hardly use this way to specify colors. So in order to specify color within this range we need to divide it using 255.0

βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
0

Replace

[cell addSubview:mantraLabel];
    [mantraLabel setTextColor:[UIColor colorWithRed:89 green:45 blue:15 alpha:1]];

With

[mantraLabel setTextColor:[UIColor colorWithRed:89/255.0f green:45/255.0f blue:15/255.0f alpha:1]];
[cell addSubview:mantraLabel];

Add your Label after set color

user1673099
  • 3,293
  • 7
  • 26
  • 57
0

The function colorWithRed:green:blue:alpha is 1 based.

i.e. 89 = 0.349 ... (89/255)

You should use...

[UIColor colorWithRed:0.349 green:0.176 blue:0.058 alpha:1.0];
Fogmeister
  • 76,236
  • 42
  • 207
  • 306