Search code examples
iosuitableviewuicolor

No response from colorWithRed


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.


Solution

  • 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