Koem
Koem

Reputation: 21

How to lock UITextField input to accept only ONE letter from A to Z on SWIFT

I have an UITextField named "TextField" and I want to get only one letter form A to Z. User will not enter more than 1 letter on this TextField. How can I do this?

Upvotes: 0

Views: 601

Answers (1)

bsarrazin
bsarrazin

Reputation: 4040

In order to control user input into a UITextField, you must implement the UITextFieldDelegate protocol in your controller.

UITextFieldDelegate Documentation

In particular, look into textField(_:shouldChangeCharactersInRange:replacementString:) and return a Bool value that allows the character or not.

Upvotes: 2

Related Questions