如何禁用或隐藏数字键盘类型的本地化?

How to disable or hide localization in Number keyboard type?

在我的 iOS 应用程序中,当用户单击 UITextfield 时,我需要自动将键盘视图更改为数字视图。我写了下面的代码,它工作正常。

UITextField *txtfield  = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
txtfield.keyboardType = UIKeyboardTypeNumberPad;

我的应用程序支持本地化。我在设备上添加了 4 个键盘,如英语、西班牙语、印地语、表情符号。我想禁用或隐藏数字键盘类型的本地化。请参阅附图。我已经用红框突出显示了。

有人知道怎么做吗?

(适用于 iOS 10 或更高版本)

Swift

使用 .asciiCapableNumberPad 表示 Xcode 8.3/Swift 3.1 仅表示数字

txtField.keyboardType = .asciiCapableNumberPad

Objective-C

txtField.keyboardType = UIKeyboardTypeASCIICapableNumberPad

@Jack 回答是正确的,但是如果你需要支持 iOS9 及以下的 iDevices,你需要这样检查:

if (IS_OS_10_OR_LATER) {
  txtfield.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
}
else {
  txtfield.keyboardType = UIKeyboardTypeNumberPad;
}

否则,如果用户的 iDevice 仍在 iOS9 及以下,用户将看到 默认 键盘类型。