How do I programmatically switch keyboard layouts on the iPad?

巧了我就是萌 提交于 2019-12-10 17:59:54

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/8071765/how-do-i-programmatically-switch-keyboard-layouts-on-the-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!