I am trying to apply NSAttributedString styles to a UITextField after processing a new text entry, keystroke by keystroke. The problem is t
Thanks @Stonz2 by the code in Objective-C. It works like a charm! I used it in my Swift project. The same code in Swift:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let positionOriginal = textField.beginningOfDocument
let cursorLocation = textField.position(from: positionOriginal, offset: (range.location + NSString(string: string).length))
/* MAKE YOUR CHANGES TO THE FIELD CONTENTS AS NEEDED HERE */
if let cursorLoc = cursorLocation {
textField.selectedTextRange = textField.textRange(from: cursorLoc, to: cursorLoc)
}
return false
}