How do I force characters input into a textbox on the iPhone to upper case?
+5
A:
Set autocapitalizationType
to UITextAutocapitalizationTypeAllCharacters
on the UITextField
.
See UITextInputTraits protocol (adopted by UITextField) for more details.
Adam Woś
2010-01-08 11:30:58
You help is good. But it isn't complete. Please see here to get my real question: http://farm5.static.flickr.com/4072/4263944357_6db39314bc.jpg
hungbm06
2010-01-11 01:45:45
Well, this is the device's behaviour, yes. If you want the letters to appear uppercase instantly, you can implement `textField:shouldChangeCharactersInRange:replacementString:` from `UITextFieldDelegate` and when a lowercase letter is entered, change it to its uppercase counterpart.
Adam Woś
2010-01-11 07:32:28
This is my code and it don't work. Inputted text still lowercase :( - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { string = [string uppercaseString]; return TRUE;}
hungbm06
2010-01-12 09:52:00
Of course it doesn't, `string` is only passed as an argument. You'll have to do something like `textField.text = [textField.text stringByReplacingCharactersInRange:range withString:[string uppercaseString]]; return NO;`
Adam Woś
2010-01-12 09:58:13
Bravo, It's done. Many thank you!!
hungbm06
2010-01-13 02:06:10