4

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?

Dog
  • 474
  • 8
  • 25

2 Answers2

4

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.

alexburtnik
  • 7,661
  • 4
  • 32
  • 70
  • 1
    Indeed, setting the switch to on will make every text field in every app to follow its capitalization. Setting the switch to off will always display the keyboard in low caps, no matter the capitalization set in app. – Dog Oct 19 '16 at 17:13
  • @WonderDog That's what I meant. `autocapitalizationType` works more like a recommendation for the system, but if user wants, he can turn that off completely. – alexburtnik Oct 19 '16 at 17:28
0

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.

Peter Brockmann
  • 3,594
  • 3
  • 28
  • 28