Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalization of UITextField

Open up Apple's Calendar app. When you name a new appointment, it automatically capitalizes the first letter. It does not use the 'correction' style swap-out to do this.

For the life of me I can not reproduce this behavior. In IB I have set the UITextField's Capitalization to Word, but it seems to have no effect at all. If I turn on correction, it will swap-out the word with a capitalized version, but this isn't quite right.

Do I need to handle this in code, by checking each key press? This is probably trivial, except I'm worried about all of the corner cases I will miss, such as when the user manually uses 'shift' to negate the capitalization, or deletes and re-keys, in which case it shouldn't capitalize.

Or maybe there's a way to simply load the textfield with shift pressed? Is this the common way of implementing it?

like image 433
Ben Packard Avatar asked Jan 15 '12 05:01

Ben Packard


4 Answers

Setting the capitalization to Word should do this, so something else is going wrong. Are you certain that's toggled on the actual UITextField that you're testing? Are you sure you're not maybe overriding it in code somehow? You can set it programmatically with:

[myTextField setAutocapitalizationType:UITextAutocapitalizationTypeWords];

There's also an exception (per the docs) where this will be ignored:

Some keyboard types do not support auto-capitalization. Specifically, this option is ignored if the value in the keyboardType property is set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or UIKeyboardTypeNamePhonePad.

Does this apply to you?

like image 112
Ben Zotto Avatar answered Nov 09 '22 22:11

Ben Zotto


Are you using the simulator or an actual device? If you are using the simulator, the casing will respect the shift and caps-lock state of the physical keyboard on your computer.

like image 27
Nathanial Woolls Avatar answered Nov 09 '22 22:11

Nathanial Woolls


i just checked this in my app and it already did Capitalization by default. the behaviour is not determined by your application code, but by the global iphone settings.

start the iOS Settings. go to General, then Keyboard, there the user has the option for "Auto-Capitalization". is it off ?

in my case it was turned on, so my app and the calendar had this feature, when i turn it off, both apps are lacking this feature, because the user decided he does not want this feature.

like image 16
JeanLuc Avatar answered Nov 09 '22 22:11

JeanLuc


Capitalization disable

textField.autocapitalizationType = UITextAutocapitalizationTypeNone;

To capitalize all characters

textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

To capitalize first character of sentence

textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;

To capitalization of first character of all words in sentense

textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
like image 5
MaxEcho Avatar answered Nov 09 '22 20:11

MaxEcho