IOS开发之带格式的文本

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


示例如下:

 

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

 

 

 

posted @ 2013-08-02 22:59  javawebsoa  Views(143)  Comments(0Edit  收藏  举报