Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numbers Keyboard in Xcode

Does any one know how to show the numbers keyboard in the iphone rather than the default one? And is there a way to filter the textfield for numbers only? I need to do that from the code not from interface builder

Thanks

like image 780
thary Avatar asked Apr 14 '10 00:04

thary


People also ask

How do I type numbers on my Apple keyboard?

When you are typing in iOS 11, you can swipe down on the upper row of letters to add numbers.


2 Answers

alternatively, set the textfield's keyboardType property in code:

textField.keyboardType = UIKeyboardTypeNumberPad

Available options are:

UIKeyboardType The type of keyboard to display for a given text-based view.

typedef enum {
UIKeyboardTypeDefault,
UIKeyboardTypeASCIICapable,
UIKeyboardTypeNumbersAndPunctuation,
UIKeyboardTypeURL,
UIKeyboardTypeNumberPad,
UIKeyboardTypePhonePad,
UIKeyboardTypeNamePhonePad,
UIKeyboardTypeEmailAddress,
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable } UIKeyboardType;

A word of caution though, The NumberPad doesn't have a decimal point for entry. If you need that you'll have to use something else.

like image 53
John Wang Avatar answered Sep 28 '22 02:09

John Wang


There's a keyboard with a decimal included now, you can use the following code.

textField.keyboardType = UIKeyboardTypeDecimalPad;

like image 27
gware Avatar answered Sep 28 '22 03:09

gware