eemceebee
eemceebee

Reputation: 2666

How to tell a UITextField to use the NumberPad Keyboard in code?

I created a UITextField in code, now I have now idea how to define the keybaord that should appear ? I just get the standard keybboard, but I need a numberpad ?!

Thanks

Upvotes: 13

Views: 8842

Answers (5)

Moriz Bühler
Moriz Bühler

Reputation: 16

You can specify the Keyboardtype like this:

.keyboardType(UIKeyboardType.numberPad)

here with some context:

@State var text : String = "" 
TextField("text", text: self.$text).keyboardType(UIKeyboardType.numberPad)

Upvotes: 0

Yunus Nedim Mehel
Yunus Nedim Mehel

Reputation: 12389

Obj-C:

textField.keyboardType = UIKeyboardTypeNumberPad;

And simply use .numberPad in Swift.

Upvotes: 12

Arash Jamshidi
Arash Jamshidi

Reputation: 171

Swift:

textField.keyboardType = .numberPad

Upvotes: 6

sam_smith
sam_smith

Reputation: 6093

You can also easily do this in the XIB file

enter image description here

Upvotes: 4

Giao
Giao

Reputation: 15146

You need to set the keyboardType property to UIKeyboardTypeNumberPad.

Upvotes: 21

Related Questions