- (void)setupDiffColorLabel:(UILabel )label WithTitle:(NSString )title WithSeparateString:(NSString )separate WithLeadColor: (UIColor )LeadColor WithTrailColor :(UIColor *)TrailColor
{
label.text = title;
label.textColor = LeadColor;
NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:label.text];
NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:separate].location);
[noteStr addAttribute:NSForegroundColorAttributeName value:TrailColor range:redRange];
[label setAttributedText:noteStr];
}
同一个label设置不同颜色文字
最新推荐文章于 2024-06-13 11:00:53 发布
本文介绍了一种在iOS开发中为UILabel设置不同部分文字颜色的方法。通过使用NSAttributedString,可以实现在同一个UILabel中不同文本片段显示不同颜色的效果。
2502

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



