UIKeyboardTypeNumberPad without a done button

前端 未结 4 1324
执笔经年
执笔经年 2020-12-15 11:09

How can we implement UIKeyboardTypeNumberPad so that it will have a \'done\' button? By default it does not have one.

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 11:55

    If I am not wrong then You want to ask as to how to add a custom "Done" button to keyboard for UIKeyboardTypeNumberPad . In that case this might be helpful. Declare a UIButton *doneButton in.h and add the following code to .m file

    - (void)addButtonToKeyboard {
        // create custom button
        if (doneButton == nil) {
            doneButton  = [[UIButton alloc] initWithFrame:CGRectMake(0, 163, 106, 53)];
        }
        else {
            [doneButton setHidden:NO];
        }
    
        [doneButton addTarget:self action:@selector(doneButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        // locate keyboard view
        UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
        UIView* keyboard = nil;
        for(int i=0; i<[tempWindow.subviews count]; i++) {
            keyboard = [tempWindow.subviews objectAtIndex:i];
            // keyboard found, add the button
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
                if([[keyboard description] hasPrefix:@"

    I am using the same in my application and the button's frame are thus adjusted, You can thus call [self addButtonToKeyboard ] whenever you need to show up the done button over the keyboard. UIKeyboardTypeNumberPad has no Done button otherwise.enter image description here

提交回复
热议问题