美文网首页
一个UILabel设置多个文字颜色

一个UILabel设置多个文字颜色

作者: hgq | 来源:发表于2016-03-23 17:29 被阅读502次

    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

    相关文章

      网友评论

          本文标题:一个UILabel设置多个文字颜色

          本文链接:https://www.haomeiwen.com/subject/uuallttx.html