iOS force App to use custom keyboard

我们两清 提交于 2019-12-11 09:47:05

问题


I am working on the app which has a one text-field which should accept only numbers so I created one custom keyboard which has only [0-9] as input to accept.To use this custom keyboard one has to go setting-->keyboards then accept this and then open particular keyboard from the app.

Is this possible to force user to open only custom keyboard without going into setting option. I want whenever user opens the app.. only custom keyboard should open, not other


回答1:


Just make it numeric by default. You could also do that from interface builder.

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

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

EDIT: Or your could use the NSNotificationCenter to inform you whether a keyboard is called and simply call your own instead:

Try something like this, didn't try myself though:

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



回答2:


Hi you can this using this code just make a view of your custom keyboard and add this line to show your keyboard instead of default keyboard

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

If you have any query then please let me know.



来源:https://stackoverflow.com/questions/24796223/ios-force-app-to-use-custom-keyboard

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