// 引入CoreText.framework
// #import <CoreText/CoreText.h>
NSString *string =
@"我是好人"@"我是好人"@"我是个好人";
// 创建可变属性化字符串
NSMutableAttributedString *attrString =
[[NSMutableAttributedString alloc] initWithString:string];
//改变字符串当中从第18位置向后的10位数的字体
UIFont *smallFont = [UIFont systemFontOfSize:12];
[attrString addAttribute:NSFontAttributeName value:smallFont range:NSMakeRange(5, 3)];
//改变字符串当中第一个“1”的颜色
UIColor *rcolor = [UIColor redColor];
[attrString addAttribute:NSForegroundColorAttributeName value:rcolor range:[string rangeOfString:@"是"]];
_label.attributedText = attrString;
实现效果:
|
|