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

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

label.attributedText = str;

效果如下图:

一个UILabel设置多个文字颜色


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

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

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-11-25
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
相关资源
相似解决方案