iOS强制应用程序使用自定义键盘

我工作的应用程序有一个text-field ,应该只接受numbers所以我创build了一个只有[0-9]作为input接受的custom keyboard要使用这个custom keyboard必须去setting – > keyboards然后接受这个,然后从应用程序打开特定的键盘。

这是否可以强制用户打开只有custom keyboard而无需进入设置选项。 我想每当用户打开应用程序.. 只有 custom keyboard应该打开,而不是其他

只需使其数字默认。 你也可以通过界面构build​​器来实现。

 UITextField *numericTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, 185, 30)]; numericTextField.adjustsFontSizeToFitWidth = YES; numericTextField.keyboardType = UIKeyboardTypeNumberPad; [parentView addSubview:numericTextField]; 

来源: 如何以编程方式在iPad上切换键盘布局?

编辑:或者你可以使用NSNotificationCenter来通知你是否有一个键盘被调用,而只需调用你自己的:

尝试这样的事情,虽然没有尝试自己:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil]; 

嗨,你可以这个使用这个代码只是看你的自定义键盘,并添加此行来显示您的键盘,而不是默认的键盘

 numericTextField.inputView = your_keyboardView;//here your_keyboardView is the object of the custom keyboard view. 

UITextField *numericTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, 185, 30)]; numericTextField.adjustsFontSizeToFitWidth = YES; numericTextField.inputView = yuor_keyboardView; [parentView addSubview:numericTextField];

如果您有任何疑问,请让我知道。