有朋友问这个~~,顺道写一下。iOS6.0以后的属性。
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"12345678"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,4)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4,4)];
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(100, 100, 100, 40);
[label setAttributedText:str];
效果: