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

26,405

Solution 1

You could use yourTextField.KeyboardType = UIKeyboardTypePhonePad if you are on a iPhone. iPad's do not support this type of keyboard. An iPad will display the NumberPad.

Solution 2

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

yourTextField.KeyboardType = UIKeyboardType.NumberPad

Solution 3

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.

Solution 4

Swift 3

In viewDidLoad write -

    mobileTextfield.keyboardType = UIKeyboardType.numberPad

you can get more choices in UIKeyboardType

Solution 5

If you are on iOS 7 use following code :

self.valueField.keyboardType = UIKeyboardTypeNumberPad;
Share:
26,405
5uperdan
Author by

5uperdan

Developer Currently working primarily with a Microsoft stack

Updated on July 09, 2022

Comments

  • 5uperdan
    5uperdan almost 2 years

    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?