如何建立三色屬性字串

 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)所以從第一個字元到第五個字元,它將以綠色文字顏色顯示。