UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 100, 20)];
textLabel.text = @"你好啊世界";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text]; // 改变特定范围颜色大小要用的
NSRange *r = NSMakeRange(1, 1);
NSRange *r2 = NSMakeRange(2, 2);
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:r];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:r2]
[label setAttributedText:attributedString];
// 这样"好"是红色的"啊世"是绿色的
iOS改变Label上指定文字的颜色
最新推荐文章于 2017-12-23 17:43:00 发布