How do I force characters input into a textbox on the iPhone to upper case?
Maybe I haven't found all the kinks to this method, but so far it works well for me. It seems to avoid the issues with jumping selection to the end if you go down the route of returning NO from -textField:shouldChangeCharactersInRange:replacementString:. Since UITextField conforms to UIKeyInput, simply override the method -insertText: to change the input string to uppercase before calling super with the uppercase string:
- (void)insertText:(NSString *)text {
NSString *uppercaseText = [text uppercaseString]
[super insertText:uppercaseText]
}
Or if you've moved along to Swift:
override func insertText(text: String) {
let uppercaseText = text.uppercaseString
super.insertText(uppercaseText)
}