IOS中一段文字设置多种字体颜色代码
给定range和需要设置的颜色,就可以给一段文字设置多种不同的字体颜色,使用方法如下:
[selffuwenbenLabel:contentLabelFontNumber:[UIFontsystemFontOfSize:15]AndRange:NSMakeRange(6,1)AndColor:RGBACOLOR(34,150,253,1)];
//设置不同字体颜色
-(void)fuwenbenLabel:(UILabel*)labellFontNumber:(id)fontAndRange:(NSRange)rangeAndColor:(UIColor*)vaColor
{
NSMutableAttributedString*str=[[NSMutableAttributedStringalloc]initWithString:labell.text];
//设置字号
[straddAttribute:NSFontAttributeNamevalue:fontrange:range];
//设置文字颜色
[straddAttribute:NSForegroundColorAttributeNamevalue:vaColorrange:range];
labell.attributedText=str;
}
以上所述就是本文的全部内容了,希望大家能够喜欢。