1

I want to allow CollectionViewCell textfield with all character(only alphabates) in uppercase with character limit 1 if user enter lowercase textfield convert it into uppercase in iOS Swift 3 ?

2 Answers2

1

In Swift 3, 4:

First add this line of code. It will Capitalized you keyboard.

yourTextField.autocapitalizationType = .allCharacters

Then set delegate to your desired textfield like that

yourTextField.delegate = self

Now implement this delegate method of textfield. This method listen your keypress.

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    // check your char limit here & capitalized char based on your requirement.
    yourTextField.text = textField.text?.uppercased()
    return true
}

Hope it helps.

Riajur Rahman
  • 1,976
  • 19
  • 28
0
yourTextfield.autocapitalizationType = .allCharacters

for character limit you can refer this : Max length UITextField

Shezad
  • 756
  • 7
  • 14