简体   繁体   English

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

[英]How do I programmatically switch keyboard layouts on the iPad?

I am having trouble finding resources on this, it may be a keyword thing. 我无法在此找到资源,它可能是一个关键词。 I am developing for the iPad, and I have text fields with numbers. 我正在为iPad开发,我有带数字的文本字段。 I understand there is not a dedicated numeric keyboard, I wish to know if there is a way after the keyboard shows to programmatically switch to the numeric view. 我知道没有专用的数字键盘,我想知道键盘显示后是否有办法以编程方式切换到数字视图。

I have seen other apps do this, so I don't think it is a matter of 'if' as much as 'how'. 我已经看到其他应用程序这样做,所以我认为这不是'如果'和'如何'一样的问题。 How do I programmatically switch keyboard layouts on the iPad? 如何以编程方式在iPad上切换键盘布局?

Set your text field's keyboardType property to UIKeyboardTypeNumberPad or UIKeyboardTypeNumbersAndPunctuation . 将文本字段的keyboardType属性设置为UIKeyboardTypeNumberPadUIKeyboardTypeNumbersAndPunctuation I think on an iPad they will currently both give you the numeric+punctuation keyboard, but perhaps a future version of iOS will have a numeric only keyboard, so you should use request one if it's more appropriate. 我认为在iPad上他们现在都会给你数字+标点符号键盘,但是未来版本的iOS可能只有一个数字键盘,所以你应该使用一个更合适的请求。

If you are creating the text field programatically: 如果以编程方式创建文本字段:

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

Or if you're using interface builder, there is a setting in the inspector pane to control the keyboard type. 或者,如果您正在使用界面构建器,则检查器窗格中有一个设置来控制键盘类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式切换 UISegmentedControl? - How do I switch UISegmentedControl programmatically? 如何从Xib文件更改iPhone和iPad中的键盘布局? - How to change Keyboard Layouts in iPhone and iPad from a xib file? 如何以编程方式填充开关盒值? - How do I programmatically populate switch case values? 广播UIKeyboardWillShowNotification时,如何知道是否使用iPad蓝牙键盘? - How do I know if the iPad bluetooth keyboard is used when UIKeyboardWillShowNotification is broadcasted? 在构建触摸键盘时,如何在ipad上支持可连接的键盘? - How do I support an attachable keyboard on ipad when building a touch keypad? 如何使用蓝牙键盘在 iPad 和 iPhone 上播放 javascript 游戏? - How can I do to make a javascript game playable on iPad and iPhone with Bluetooth keyboard? 如何在启动时以编程方式强制iPad进入1x或2x模式? - How do I force iPad to 1x or 2x mode programmatically at startup? 如何以编程方式强制浮动键盘? - How can I force a floating keyboard programmatically? 如何在进入我的应用程序时自动切换到 iOS 自定义键盘? - How do I automatically switch to the iOS custom keyboard when entering my app? 如果我以编程方式完成所有布局,是否需要启用 Base Internationalization? - Do I need to enable Base Internationalization if I do all layouts programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM