如何以编程方式在iPad上切换键盘布局? [英] How do I programmatically switch keyboard layouts on the iPad?
问题描述
我无法在此找到资源,这可能是一个关键词。我正在为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. 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.
我见过其他应用程序这样做,所以我不认为这是'如果'和'如何'一样多的问题。如何以编程方式在iPad上切换键盘布局?
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?
推荐答案
设置文本字段的 keyboardType
属性为 UIKeyboardTypeNumberPad
或 UIKeyboardTypeNumbersAndPunctuation
。我认为在iPad上他们现在都会给你数字+标点键盘,但是未来版本的iOS可能只有一个数字键盘,所以你应该使用一个更合适的请求。
Set your text field's keyboardType
property to UIKeyboardTypeNumberPad
or UIKeyboardTypeNumbersAndPunctuation
. 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.
如果您以编程方式创建文本字段:
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.
这篇关于如何以编程方式在iPad上切换键盘布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!