<span style="font-size:18px;">UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, kWidth - 100, 50)];
// 创建一个NSAttributedString
NSMutableAttributedString *num = [[NSMutableAttributedString alloc] initWithString:@"12000.00% "];
// 设置字体的颜色
[num addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,6)];
[num addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(6,2)];
// 更改字体大小
[num addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, 6)];
// 在文本下面添加下划线
[num addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, 6)];
// label添加文本
label.attributedText = num;
// 设置label的背景颜色
label.backgroundColor = [UIColor whiteColor];
[self.view addSubview:label];</span>
Vickate_NSAttributedString简单使用
最新推荐文章于 2017-04-01 15:16:49 发布