Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

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 }

 

posted on 2016-03-01 17:14  Sinner_Yun  阅读(237)  评论(0编辑  收藏  举报

导航