I want to be able to replace some text in an UITextView programatically, so I wrote this method as an UITextView category:
- (void) replaceCharactersInRange:(NSR
There is actually no reason for any hacks or custom categories to accomplish this. You can use the built in UITextInput Protocol method replaceRange:withText:
. For inserting text you can simply do:
[textView replaceRange:textView.selectedTextRange withText:replacementText];
This works as of iOS 5.0. Undo works automatically and there are no weird scrolling issues.