美文网首页
(IOS)设置textView的某段文字变成其他颜色

(IOS)设置textView的某段文字变成其他颜色

作者: rightmost | 来源:发表于2018-08-10 17:41 被阅读0次

 - (void)setupTextView:(UITextView *)textView text:(NSString *)text color:(UIColor *)color {

        NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:textView.text];

        [string addAttribute:NSForegroundColorAttributeName value:color range:[textView.text rangeOfString:text]];

        [textView setAttributedText:string];

    }

相关文章

网友评论

      本文标题:(IOS)设置textView的某段文字变成其他颜色

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