一个UILabel设置多个文字颜色

2016-03-23  本文已影响502人  hgq

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"我是中国人我爱中国"];

[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5, 3)];

label.attributedText = str;

效果如下图:

其中 NSForegroundColorAttributeName 来自NSAttributedString类,可以设置字体种类、大小、颜色、下划线,具体可以点进去看

还有一个关于各种字体的网址:读完它iOS字体就没什么难的了!

以及:Text Kit学习(入门和进阶)objc系列译文(5.1):认识 TextKit

上一篇下一篇

猜你喜欢

热点阅读