NSString* str=@“颜色分段显示”;
NSMutableAttributedString *coloredStr = [[NSMutableAttributedString alloc] initWithString:str];
[coloredStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,2)];
[coloredStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(2,4)];
效果为 “颜色”显示红色 “分段显示”显示黑色。