Create a three-color attributed string
suggest changeNSMutableAttributedString * 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents