0

I have 2 UITextFields that have UITextAutocapitalizationType set to .sentences. I would like for the second UITextField to begin with a lowercase letter if the first UITextField does not end with a Period or Questionmark. I can programmatically set the first letter to lowercase, however, I have no way to enable the user to override it to capital and I want them to be able to do this.

The approach I took was if the first UITextField does not end with a period or question mark to set the second UITextField's UITextAutocapitalizationType to .none. Once the user gets past their first character in the second text field, I set the UITextAutocapitalizationType back to .sentences. The problem I'm encountering is that it doesn't appear that the UITextField knows to update its UITextAutocapitalizationType while the user is typing. It waits until I leave the UITextField and return to it.

I have tried forcing a refresh on the second UITextfield, but that didn't solve the problem.

Any help would be appreciated.

quant24
  • 393
  • 6
  • 22
Matty8r
  • 31
  • 5
  • Why do you want to set the autocapitalization back to "Sentence" immediately after the user typing? The last character in the first text field is still not a '.' or '?' right? – Rakesha Shastri Sep 06 '18 at 02:25
  • This may help you - https://stackoverflow.com/questions/29261218/how-to-capitalize-each-word-in-a-string-using-swift-ios – teja_D Sep 06 '18 at 05:11

1 Answers1

0

Once the user gets past their first character in the second text field, then you need to set first character of each sentence capitalised programmatically in the following method:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

}
Mahak Mittal
  • 121
  • 1
  • 10