美文网首页
字符串的截取-设置字符串中某些文字的颜色

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

作者: 闲云悠鹤蝶恋舞 | 来源:发表于2016-06-24 19:28 被阅读347次

效果图:

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; 

相关文章

网友评论

      本文标题:字符串的截取-设置字符串中某些文字的颜色

      本文链接:https://www.haomeiwen.com/subject/veoodttx.html