this code is working in ios 6,7,8 but this all method is called in ios 9 but it is not visible. on number pad. here is my code.
#import \"ViewController.h\"
First of all we are declaring new variable:
@property (strong, nonatomic) UIButton *doneButton;
Call button initialization in viewDidLoad
:
- (void)setupDoneButton {
if (!self.doneButton) {
self.doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.doneButton addTarget:self action:@selector(tapGestureRecognizerAction) forControlEvents:UIControlEventTouchUpInside];
self.doneButton.adjustsImageWhenHighlighted = NO;
[self.doneButton setTitle:@"DONE" forState:UIControlStateNormal];
[self.doneButton.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
[self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
}
}
Show button in keyboardDidShow
or textFieldDidBeginEditing
method:
- (void)addDoneButtonToKeyboard {
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow *keyboardWindow = [[[UIApplication sharedApplication] windows] lastObject];
CGFloat buttonWidth = CGRectGetWidth(keyboardWindow.frame)/3;
self.doneButton.frame = CGRectMake(0.f, CGRectGetHeight(keyboardWindow.frame) - 53, buttonWidth, 53);
[keyboardWindow addSubview:self.doneButton];
[keyboardWindow bringSubviewToFront:self.doneButton];
});
}
Than remove button in keyboardWillHide
or textFieldDidEndEditing
method:
[self.doneButton removeFromSuperview];
This works on both iOS8 and iOS9.