iOS为一段文字显示不同的颜色
2016-11-11 16:12
453 查看
//需求:0次为红色
NSString
*str =
@"您有0次拆红包的机会";
NSMutableAttributedString
*attributedStr = [[NSMutableAttributedString
alloc]initWithString:str];
UIColor
*color = [AppUtils
callColorFromHexRGB:@"5f5f5f"];
[attributedStr
addAttribute:NSForegroundColorAttributeName
value:color
range:[str
rangeOfString:@"您有
次拆红包的机会"]];
UIColor
*color1 = [UIColor
redColor];
[attributedStr
addAttribute:NSForegroundColorAttributeName
value:color1
range:[str
rangeOfString:@"0"]];
//设置label的行间距
NSMutableParagraphStyle
*paregraphStyle = [[NSMutableParagraphStyle
alloc]
init];
[paregraphStyle
setLineSpacing:10.0];
[attributedStr
addAttribute:NSParagraphStyleAttributeName
value:paregraphStyle
range:NSMakeRange(0,
str.length)];
hLabel
= [[UILabel
alloc]init];
hLabel.attributedText
= attributedStr;
NSString
*str =
@"您有0次拆红包的机会";
NSMutableAttributedString
*attributedStr = [[NSMutableAttributedString
alloc]initWithString:str];
UIColor
*color = [AppUtils
callColorFromHexRGB:@"5f5f5f"];
[attributedStr
addAttribute:NSForegroundColorAttributeName
value:color
range:[str
rangeOfString:@"您有
次拆红包的机会"]];
UIColor
*color1 = [UIColor
redColor];
[attributedStr
addAttribute:NSForegroundColorAttributeName
value:color1
range:[str
rangeOfString:@"0"]];
//设置label的行间距
NSMutableParagraphStyle
*paregraphStyle = [[NSMutableParagraphStyle
alloc]
init];
[paregraphStyle
setLineSpacing:10.0];
[attributedStr
addAttribute:NSParagraphStyleAttributeName
value:paregraphStyle
range:NSMakeRange(0,
str.length)];
hLabel
= [[UILabel
alloc]init];
hLabel.attributedText
= attributedStr;
相关文章推荐
- iOS 同一段文字显示不同颜色
- iOS开发 - 同一段文字显示不同颜色和字体
- iOS开发-同一段文字显示不同颜色
- iOS - lable的text中不同字符不同颜色设置,一段文字显示多重颜色
- iOS label的文字显示不同的颜色
- iOS - UILabel一段文字加不同下划线加不同颜色
- iOS开发~设置label上文字显示不同大小、颜色、字体类型
- ios UILabel显示不同颜色的文字
- iOS 开发~设置label上文字显示不同大小、颜色、字体类型
- iOS 一个label中显示不同颜色的文字
- iOS 在一个UILabel里显示不同的颜色,给文字加下划线
- ios Label上显示不同颜色文字
- ios Label显示不同颜色文字
- iOS 一个label中显示不同颜色的文字
- iOS UILabel显示文字设置不同的颜色以及行间距
- 一段文字内有不同颜色字体交叉显示
- IOS 富文本---关于如何处理在一段文字中突出显示某几个字段大小或者颜色的处理
- iOS 在一个UILabel里显示不同的颜色,给文字加下划线
- iOS 在UILabel显示不同的字体和颜色
- iOS 在UILabel显示不同的字体和颜色