天天看点

设置label的文字,一行多种颜色

调用

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/lhw91/p/5687602.html