iOS一段文字设置多种颜色格式

调用

 1 [self fuwenbenLabel:contentLabel FontNumber:[UIFont systemFontOfSize:15] AndRange:NSMakeRange(6, 1) AndColor:RGBACOLOR(34, 150, 253, 1)]; 

方法

 1 //设置不同字体颜色
 2 -(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
 3 {
 4     NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text];
 5 
 6     //设置字号
 7     [str addAttribute:NSFontAttributeName value:font range:range];
 8 
 9     //设置文字颜色
10     [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
11 
12     labell.attributedText = str;
13 }
让明天,不后悔今天的所作所为
原文地址:https://www.cnblogs.com/-yun/p/5231778.html