1

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

Andrew
  • 15,357
  • 6
  • 66
  • 101
user3226440
  • 559
  • 1
  • 8
  • 23
  • Why not make it numeric by default? UITextField *numericTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, 185, 30)]; numericTextField.adjustsFontSizeToFitWidth = YES; numericTextField.keyboardType = UIKeyboardTypeNumberPad; [parentView addSubview:numericTextField]; – Akaino Jul 17 '14 at 06:25
  • wy dont u set `_textField.keyboardType = UIKeyboardTypeNumberPad` for this textfield the keyboard shows only number pad – Shankar BS Jul 17 '14 at 06:29
  • @Shan I want to set the custom keyboard for iOS8 not the apple's default keyboard – user3226440 Jul 17 '14 at 06:38
  • @user3226440: What we're trying to ask is: Is there any specific reason you want to re-invent the wheel? There already is a numeric keyboard, so why do you want to implement your own? – DarkDust Jul 17 '14 at 07:17

2 Answers2

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];
Community
  • 1
  • 1
Akaino
  • 1,025
  • 6
  • 23
1

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.

Nitin
  • 1,383
  • 10
  • 19