Create a three-color attributed string

suggest change
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"firstsecondthird"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];

Each range is (location, length). In @"firstsecondthird", (0, 5) is “first” and is red, (5, 6) is “second” and is green, and (11, 5) is “third” and is blue.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents