Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Field keyboard set to Number Pad but regular keyboard is displaying on selection

I have set my text field's keyboard to 'Number Pad' in the xcode designer which adds the following code between my tags in my .xib

<textInputTraits key="textInputTraits"
autocorrectionType="no" keyboardType="numberPad"/>

I had expected that when selecting this textfield, the following keyboard input would appear:

enter image description here

But instead, the following input is appearing:

enter image description here

How can i set my text field to use the first input (or similar) instead of the second?

like image 683
5uperdan Avatar asked Mar 12 '14 10:03

5uperdan


3 Answers

As of Swift 3, it is now a little different. For a UITextField, e.g. height, it'll be like this:

@IBOutlet weak var height: UITextField!

height.keyboardType = UIKeyboardType.numbersAndPunctuation

OR

height.keyboardType = UIKeyboardType.numberPad

Now when you press the text field, proper keyboard will popup.

like image 182
zeeshan Avatar answered Nov 15 '22 21:11

zeeshan


You can set keyboardType property of UITextFiled to UIKeyboardTypePhonePad as follows:

yourTextField.KeyboardType = UIKeyboardType.NumberPad
like image 32
Sujith Thankachan Avatar answered Nov 15 '22 19:11

Sujith Thankachan


Swift 3

In viewDidLoad write -

    mobileTextfield.keyboardType = UIKeyboardType.numberPad

you can get more choices in UIKeyboardType

like image 44
Khushboo Dhote Avatar answered Nov 15 '22 20:11

Khushboo Dhote