chang color of some characters in a string

来源:互联网 发布:外文数据库哪个好 编辑:程序博客网 时间:2024/06/06 19:25

 //先把这个string取出来,转化一下属性

NSMutableAttributedString *str = [[NSMutableAttributedStringalloc] initWithString:_interstnumLabel.text];

//建立字典

 NSDictionary *dict = [[NSDictionaryalloc] initWithObjectsAndKeys:[UIColoryellowColor],NSForegroundColorAttributeName,nil];

//调用改变属性方法

 [str setAttributes:dictrange:NSMakeRange(0,2)];

//重新赋给源本

 _interstnumLabel.attributedText = str;

0 0