Reputation: 494
I have created a new project that only has one text field and I set the capitalization to all characters. I tried this from both interface builder and code:
[self.textField setAutocapitalizationType:UITextAutocapitalizationTypeAllCharacters];
No matter what I try, this is the result:
I am aware that the keyboard Auto-Capitalization settings can be changed from Settings - General - Keyboard - Auto-Capitalization, but I assume there would be no purpose in having the AutocapitalizationType property on a text field if it is overwritten by the iOS anyway.
It is also not working for UITextAutocapitalizationTypeWords.
This is happening on iOS 10.0.2 on an iPhone 6S (other answers say that it happens in simulator, but this is not the case).
Any idea what is the issue?
Upvotes: 4
Views: 1801
Reputation: 3704
One way I enforced an all-caps presentation in textField regardless of the autocapitalization directive, was to insert this little twist in the UITextFieldDelegate func:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let str = string.capitalized
let result = (textField.text as NSString?)?.replacingCharacters(in: range, with: str) ?? str
textField.text = result
return false
}
This will capitalize inserted characters too, as expected.
Upvotes: 0
Reputation: 7741
I am aware that the keyboard Auto-Capitalization settings can be changed from Settings - General - Keyboard - Auto-Capitalization, but I assume there would be no purpose in having the AutocapitalizationType property on a text field if it is overwritten by the iOS anyway.
You're right, the this switch in settings should be on. But it does not override the value of textfields in an app. If this toggle is on, all textfields which want to capitilize user's input will be allowed to do so and textfields with UITextAutocapitalizationTypeNone
value won't capitalize anything.
Upvotes: 4