美文网首页
iOS 改变字符串局部颜色

iOS 改变字符串局部颜色

作者: 夜冰雨 | 来源:发表于2020-03-09 17:36 被阅读0次

NSString *textStr = [NSString stringWithFormat:@"%@:%@",@"今天天气好吗?".@"不好,外面都没有太阳"];

NSString *nameStr = [NSString stringWithFormat:@"%@:",@"今天天气好吗?"];

 NSString*messageStr = [NSStringstringWithFormat:@"%@",@"不好,外面都没有太阳"];

 NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:textStr];

  attrsaddAttribute:NSForegroundColorAttributeName value:[NIMKit sharedKit].config.nickColor range:[textStr rangeOfString:nameStr]];

   [attrsaddAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:[textStr rangeOfString:messageStr]];

     self.nameLabel.attributedText= attrs;

相关文章

网友评论

      本文标题:iOS 改变字符串局部颜色

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