im triyin to format a word from keyboard input in a uitextfield,
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
let words = textView.text.components(separatedBy: " ")
for word in words{
if word.hasPrefix("@"){
let attributes = [NSForegroundColorAttributeName: UIColor.blue, NSFontAttributeName: self.textView.font!] as [String : Any]
let attributedString = NSMutableAttributedString(string: word, attributes: attributes)
self.textView.textStorage.insert(attributedString, at: range.location)
let cursor = NSRange(location: self.textView.selectedRange.location+1, length: 0) //textView.text.range(of: word)
textView.selectedRange = cursor
return true
}
}
return true
}
any ideas how to ge it done the expected result should be @yoel l