iOS-Label中字符显示

来源:互联网 发布:精易模块源码 编辑:程序博客网 时间:2024/06/17 07:17

有时可能会遇到这样的问题,一个label中设置的文本含有2种以上不同的格式,又不能把它拆解为两个label来显示,这时用NSMutableAttributedString可以很好的解决问题。


示例如下:

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: label.attributedText];    [text addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(10, 1)];    [label setAttributedText: text];


0 0
原创粉丝点击