How to limit iOS keyboard to numeric input
The question 开发者_高级运维pretty much says it all. Is there any way to have the iOS/iPhone keyboard default to numeric input?
Set the keyboardType
property of the UITextField
to UIKeyboardTypeDecimalPad
.
Swift 3
yourUITextField.keyboardType = .decimalPad
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;
精彩评论