The question pretty much says it all. Is there any way to have the iOS/iPhone keyboard default to numeric input?
Asked
Active
Viewed 2.9k times
31
-
possible duplicate of [how convert keyboard type in iphone](http://stackoverflow.com/questions/6200941/how-convert-keyboard-type-in-iphone) – Jason Sep 14 '11 at 00:31
2 Answers
60
Set the keyboardType
property of the UITextField
to UIKeyboardTypeDecimalPad
.
Swift 3
yourUITextField.keyboardType = .decimalPad
-
9by doing this you get a keyboard that does not have a "return" or "ok" button, so the solution is more complex, I used UIKeyboardTypeNumbersAndPunctuation which gives the normal keyboard but shifted to the number input, it includes a return key. – godzilla Jun 05 '13 at 21:03
-
@godzilla : If you care for return key, you can use [IQKeyboardManager](https://github.com/hackiftekhar/IQKeyboardManager) which will add Done button on the top of keyboard and this library help you for other many issues... – Fahim Parkar Nov 20 '17 at 07:47
2
Objective-C:
Default to Numbers (but include - and . if you need to allow decimal or negative numbers):
myTextField1.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
Default to Numbers (#s only for integer values)
myTextField1.keyboardType=UIKeyboardTypeNumberPad;

Vette
- 511
- 5
- 10