UIKeyboardTypeNumberPad returns or makes a button in iOS 5

In iOS 3, this workaround involves creating a client-side UIButton and adding it as a subquery to the Apple keyboard. When iOS 4 was released, it was revealed that the subtitle was added to the modified one. Therefore, to work in iOS3 and 4, I had the following.

-(void) addDoneButtonToNumericKeyboard { if(doneButtonIsAdded) { return; } if(doneButtonForNumericKeyboard == nil) { doneButtonForNumericKeyboard= [[UIButton buttonWithType:UIButtonTypeCustom] retain]; doneButtonForNumericKeyboard.frame = CGRectMake(0, 163, 106, 53); doneButtonForNumericKeyboard.adjustsImageWhenHighlighted = NO; if ([[[UIDevice currentDevice] systemVersion] hasPrefix:@"3"]) { [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal]; [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted]; } else { [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal]; [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted]; } [doneButtonForNumericKeyboard addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside]; } // locate keyboard view NSArray *winArray = [[UIApplication sharedApplication] windows]; if(winArray == nil || [winArray count] < 2) { NSLog(@"No winArray found!"); return; } UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; UIView* keyboard; for(int i=0; i<[tempWindow.subviews count]; i++) { keyboard = [tempWindow.subviews objectAtIndex:i]; // keyboard view found; add the custom button to it NSLog(@"Keyboard description : %@", [keyboard description]); if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES || [[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) { NSLog(@"Attaching done button"); [keyboard addSubview:doneButtonForNumericKeyboard]; doneButtonIsAdded = YES; } } } 

Anyone have any ideas how to do this for iOS 5?

None of the above methods work for 5. There is an attempt to add a subview that seems successful but doesn't display anything. The area is simply blank on the screen and does not respond to touch.

+6
source share
2 answers

I noticed this too, and the only fix I could come up with was to change it: keyboardWillShow: to keyboardDidShow: The difference between β€œwill” and β€œmade” is obviously another discussion, but it seems to be fixed for my needs.

Hope this helps.

Another example of what I found is that the [[UIApplication sharedApplication] windows] first object seems to exist, but the second object with index 1 has disappeared. I wonder what caused this.

Thanks.

+9
source

I was fortunate enough to find this:

Replace: if ([[keyboard description] hasPrefix: @ "

C: if ([[[UIDevice currentDevice] systemVersion] floatValue]> = 3.2) {if ([[keyboard description] hasPrefix: @ "

Link to this link: UIKeyboardTypeNumberPad without a button made

0
source

Source: https://habr.com/ru/post/899295/


All Articles