【问题标题】:iOS force App to use custom keyboardiOS 强制 App 使用自定义键盘
【发布时间】:2014-07-17 06:23:06
【问题描述】:

我正在开发一个应用程序,它有一个text-field,它应该只接受numbers,所以我创建了一个custom keyboard,它只有[0-9] 作为接受的输入。要使用这个custom keyboard,必须转到setting-->keyboards 然后接受这个,然后从应用程序中打开特定的键盘。

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

【问题讨论】:

  • 为什么不默认设为数字呢? UITextField *numericTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, 185, 30)]; numericTextField.adjustsFontSizeToFitWidth = YES; numericTextField.keyboardType = UIKeyboardTypeNumberPad; [parentView addSubview:numericTextField];
  • 你不要为这个文本字段设置_textField.keyboardType = UIKeyboardTypeNumberPad,键盘只显示数字键盘
  • @Shan 我想为 iOS8 设置自定义键盘,而不是苹果的默认键盘
  • @user3226440:我们想问的是:您有什么特别的理由要重新发明轮子吗?数字键盘已经有了,为什么还要自己实现呢?

标签: ios iphone ios8 ios-app-extension uiinputviewcontroller


【解决方案1】:

默认设置为数字即可。您也可以从界面生成器中执行此操作。

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

来源:How do I programmatically switch keyboard layouts on the iPad?

编辑: 或者您可以使用 NSNotificationCenter 通知您是否调用了键盘,而只需调用您自己的:

尝试这样的事情,但我自己没有尝试:

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

【讨论】:

  • 嗨。我想设置我为 iOS8 创建的自定义键盘。不是 Apple 默认键盘..
【解决方案2】:

您好,您可以使用此代码查看您的自定义键盘并添加此行以显示您的键盘而不是默认键盘

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];

如果您有任何疑问,请告诉我。

【讨论】:

    猜你喜欢
    • 2013-11-10
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 2020-12-04
    • 2015-06-09
    相关资源
    最近更新 更多