Reputation: 2206
In my iOS app, when the user click on a UITextfield
I need to change the keyboard view to the numeric view automatically. I write below code and it is working fine.
UITextField *txtfield = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
txtfield.keyboardType = UIKeyboardTypeNumberPad;
My app supports localization. I added 4 keyboards on the device like English, Spanish, Hindi, Emoji. I want disable or hide localization in number keyboard type. Please see attached image. I have highlighted in red box.
Anyone knows how to do that?
Upvotes: 7
Views: 3264
Reputation: 14329
(Applies for iOS 10 or later)
Swift
Use .asciiCapableNumberPad
for Xcode 8.3/Swift 3.1 for only numbers
txtField.keyboardType = .asciiCapableNumberPad
Objective-C
txtField.keyboardType = UIKeyboardTypeASCIICapableNumberPad
Upvotes: 11
Reputation: 145
@Jack answer is correct but if you need to support iDevices with iOS9 and below, you need to put a check like this:
if (IS_OS_10_OR_LATER) {
txtfield.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
}
else {
txtfield.keyboardType = UIKeyboardTypeNumberPad;
}
If not, the users will see a Default keyboard type if their iDevice is still on iOS9 and below.
Upvotes: 3