NSRange titleRange = [commentStr rangeOfString:title];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:commentStr]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:titleRange];
本文展示了一个使用 NSAttributedString 的示例,演示如何为字符串中特定范围的文字设置颜色。通过 NSRange 和 addAttribute 方法,实现了对评论字符串中特定标题部分进行样式更改的功能。
900

被折叠的 条评论
为什么被折叠?



