Numbers Keyboard in Xcode

thary picture thary · Apr 14, 2010 · Viewed 30.4k times · Source

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

Answer

John Wang picture John Wang · Apr 14, 2010

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.