您的位置:首页 > 其它

字符串的截取-设置字符串中某些文字的颜色

2017-06-28 00:00 197 查看
效果图:



Snip20160624_1.png

注意:

1、其中count是一个数字,例如:5,即5人赞过中的数字5。
2、_countLabel 是UILabel类型的一个控件。

// 通过截取的方式,来设置***人赞过中数字的颜色
NSString*string = [NSString stringWithFormat:@"%ld人赞过",(long)count];
NSMutableAttributedString*attributeString = [[NSMutableAttributedStringalloc] initWithString:string];

NSRange range = [string rangeOfString:[NSString stringWithFormat:@"%ld",(long)count]];

[attributeString addAttribute:NSForegroundColorAttributeName value:RGBCOLOR(246, 153,19) range:range];

// 使用UILabel的attributedText 属性来赋值。
_countLabel.attributedText= attributeString;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: