Reputation: 2451
Is there a native UI control for code input text field, for example like Whatsapp:
Upvotes: 1
Views: 4320
Reputation: 2893
In the past I've added a UITextField to the view and set its hidden == true. Then I show/hide the keyboard by calling becomeFirstResponder()/resignFirstResponder() on it. I listen for text did change notifications and update a visible label with the value of the hidden text field.
Upvotes: 1
Reputation: 126319
There's a 4-digit code input text field called CodeInputView written in Swift.
Upvotes: 1
Reputation: 6269
No. To achieve this, they're almost certainly tapping into the textField:shouldChangeCharactersInRange:replacementString: method for their UITextField
, selectively accepting and formatting user input to match the dash-if-empty approach.
Further, I'm sure they've subclassed the field; per your comments there isn't a blue cursor - which isn't standard for a UITextField
.
Upvotes: 1
Reputation: 130193
No there isn't. Use a UITextField
, fill it with dashes, keep track of how many characters the user has entered, and replace the dashes accordingly as the user types.
Upvotes: 1