UILabel 添加下划线,改变字体颜色,NSMutableAttributedString实现富文本

        NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:model.textMsg];

        NSRange strRange = {0,[attributedStr length]};

       //加颜色

 [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:strRange];

       //加下划线

 [attributedStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];

        self.contentLabel.attributedText = attributedStr;

你可能感兴趣的:(IOS技术)