Вы можете сделать это легко, сделав расширение для UITextView
extension UITextView {
func halfTextColorChange (fullText : String , changeText : String ) {
let strNumber: NSString = fullText as NSString
let range = (strNumber).range(of: changeText)
let attribute = NSMutableAttributedString.init(string: fullText)
attribute.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor(red: 76/255, green: 76/255, blue:76/255, alpha: 1.0) , range: range)
self.attributedText = attribute
}
}
Использование
txtView.halfTextColorChange(fullText: "ABCXYZ", changeText: "XYZ")