1

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

enter image description here

jscs
  • 63,095
  • 13
  • 148
  • 192
Mario
  • 2,331
  • 6
  • 25
  • 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
  • 126,953
  • 40
  • 282
  • 279
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
  • 5,989
  • 2
  • 29
  • 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
  • 113,928
  • 113
  • 437
  • 631
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,846
  • 1
  • 25
  • 30