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 ?
Asked
Active
Viewed 72 times
2 Answers
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
-
yourTextfield.autocapitalizationType = .allCharacters. This is not working for all text in textfield. – Rupshikha anand Jan 09 '18 at 10:48
-
try this http://beyond925.blogspot.in/2015/09/ios-swift-force-all-characters-to-be.html – Shezad Jan 09 '18 at 11:43