[英]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
属性设置为UIKeyboardTypeNumberPad
或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. 我认为在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.