如何创建三色属性字符串

 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)];

范围:开始结束字符串

这里我们有第一个第二个字符串,所以首先我们设置范围(0,5)所以从第一个字符到第五个字符,它将以绿色文本颜色显示。