一个label显示多种颜色,多种字体大小,并非多个label拼接而成。
UILabel* label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 100, 200, 100);
label.textColor = [UIColor blackColor];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"1234567890"];
NSRange range = NSMakeRange(0, [[str string] rangeOfString:@"5"].location);
//NSRange range = NSMakeRange(0,6); //这里是设置从第一个字符到第六个字符
[str addAttribute:NSForegroundColorAttribute

本文探讨如何使用NSAttributedString让一个UILabel显示多种颜色和字体大小,而无需将多个label进行拼接。通过研究NSAttributedString的21种属性设置,实现更灵活的文字展示。

2万+

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



