Peer Mohamed Thabib
Peer Mohamed Thabib

Reputation: 705

Done button in NumberKeyPad Causing Issue in iOS 8

Code Used to add done button in Numberkeypad

- (void)keyboardWillShow:(NSNotification *)note {
    // create custom button
    doneButton = [[UIButton alloc]init];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setTitle:@"Done" forState:UIControlStateNormal];
    [doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [doneButton addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];

    if (IS_iOS_7_OR_LATER) {
        dispatch_async(dispatch_get_main_queue(), ^{
            UIView *keyboardView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] firstObject];
            [doneButton setFrame:CGRectMake(0, keyboardView.frame.size.height - 53, 106, 53)];
            [keyboardView addSubview:doneButton];
            [keyboardView bringSubviewToFront:doneButton];

            [UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]-.02
                                  delay:.0
                                options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]
                             animations:^{
                                 self.view.frame = CGRectOffset(self.view.frame, 0, 0);
                             } completion:nil];
        });
    }else {
        // locate keyboard view
        dispatch_async(dispatch_get_main_queue(), ^{
            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
                if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
                    [keyboard addSubview:doneButton];
            }
        });
    }
}

I have written code to add done button in number keypad its working perfectly with device's default keyboard the problem arises if the device is installed with third party keyboard [swift keys App] is there a way to identify the third party Keyboard to solve this issue

Thanks in Advance!

Device Default Keyboard Device Installed With Custom Keyboard

Upvotes: 1

Views: 897

Answers (1)

Yılmaz G&#252;rsoy
Yılmaz G&#252;rsoy

Reputation: 162

if you want, I know one way but exactly not you said; You don't need any third party library for this method you just create UIBarButton and add button to UIToolbar and finally just add you created toolbar after you implement it

YourNumberTextField.inputAccessoryView = textFieldToolBar;

here is a code

UIToolbar* textFieldToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
textFieldToolBar.barStyle = UIBarStyleBlackTranslucent;
textFieldToolBar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithTitle:@"Clear All" style:UIBarButtonItemStyleBordered target:self action:@selector("YourClearButtonFunctionName")],
                       [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                       [[UIBarButtonItem alloc]initWithTitle:@"Ok!" style:UIBarButtonItemStyleDone target:self action:@selector("YourOkButtonFunctionName")],
                       nil];
[textFieldToolBar sizeToFit];
YourNumberTextField.inputAccessoryView = textFieldToolBar;

Upvotes: 1

Related Questions