富文本 指定文字变红

image.png
 //MARK  富文本部分字体变红
    func setupAttributeString(text : NSString, highlightText : NSString) -> NSMutableAttributedString {
        let hightlightTextRange = text.range(of: highlightText as String)
        let attributeStr = NSMutableAttributedString.init(string: text as String)
        attributeStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range: hightlightTextRange)
        return attributeStr
    }

你可能感兴趣的:(富文本 指定文字变红)