您的位置:首页 > 移动开发 > IOS开发

iOS lable内容格式的设置

2015-08-20 09:25 531 查看
一个label中设置的文本含有2种以上不同的格式,又不能把它拆解为两个label来显示,这时用NSMutableAttributedString可以很好的解决问题。

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: label.attributedText];

[text addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(10, 1)];

[label setAttributedText: text];

设置不同字体颜色

-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor

{

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text];

//设置字号

[str addAttribute:NSFontAttributeName value:font range:range];

//设置文字颜色

[str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];

labell.attributedText = str;

}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: