Is there a way to have the textColor
property of a UILabel
be two different UIColors
? Basically I'm trying to make the first character in the UILabel
text property
to be greenColor
and the rest be blackColor
. I would like to avoid using two different UILabels
because I may want to change the position in the text of the green character.
Starting from ios 6 you can do the following :
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
[attributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,3)];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(4,9)];
cell.label.attributedText = attributedString;