views:

544

answers:

1

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ś
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
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ś
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
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ś
Bravo, It's done. Many thank you!!
hungbm06