I am trying to apply NSAttributedString styles to a UITextField after processing a new text entry, keystroke by keystroke. The problem is t
This is an old question, but I had a similar issue and resolved it with the following Swift:
// store the current cursor position as a range
var preAttributedRange: NSRange = textField.selectedRange
// apply attributed string
var attributedString:NSMutableAttributedString = NSMutableAttributedString(string: fullString)
attributedString = format(textField.text) as NSMutableAttributedString
textField.attributedText = attributedString
// reapply the range
textField.selectedRange = preAttributedRange
It works in the context of my app, hopefully it's useful for someone!