I'm trying to change a UILabels
first line's color. It's not working for some reason. Here is my code:
NSMutableAttributedString *text =
[[NSMutableAttributedString alloc]
initWithAttributedString: label.attributedText];
[text addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:[label.text rangeOfString:@"\n"];];
[label setAttributedText: text];
I don't see any changes in the first line.
The problem is here
It will color only
\n
You need range from
0
to start of\n
Edit : You can try this code (it's not tested but should work)