1

Is there a native UI control for code input text field, for example like Whatsapp:

enter image description here

jscs
  • 63,694
  • 13
  • 151
  • 195
Mario
  • 2,431
  • 6
  • 27
  • 34

4 Answers4

1

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.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
1

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.

jterry
  • 6,209
  • 2
  • 30
  • 36
  • any idea how to hide the cursor? – Mario Feb 05 '14 at 15:39
  • Maybe [this](http://stackoverflow.com/questions/3699727/hide-the-cursor-of-an-uitextfield) or [this](http://stackoverflow.com/questions/11525255/uitextview-hide-cursor-change-color-of-cursor) or [this](http://pastebin.com/Gw7dPnJc)... – jterry Feb 05 '14 at 16:20
1

There's a 4-digit code input text field called CodeInputView written in Swift.

ma11hew28
  • 121,420
  • 116
  • 450
  • 651
1

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.

Tylerc230
  • 2,883
  • 1
  • 27
  • 31