在项目中我们经常需要用到在一个label上的字体显示不同的颜色,下面就是我经常采用的一种方法
NSString *submitApplyStr = @"*是否提交预约申请";
NSMutableAttributedString *mutSubmitApplyStr = [[NSMutableAttributedString alloc] initWithString:submitApplyStr];
[mutSubmitApplyStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#f90800"] range:NSMakeRange(0, 1)];
submitApplyLabel.attributedText = mutSubmitApplyStr;简单的例子 供大家参考
本文介绍了一种在iOS开发中为UILabel设置部分文字不同颜色的方法。通过使用NSMutableAttributedString并结合NSForegroundColorAttributeName属性,可以轻松实现这一效果。
8703

被折叠的 条评论
为什么被折叠?



