UIKeyboardTypeNumberPad without a done button

前端 未结 4 1269
执笔经年
执笔经年 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:51

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
    
    
    //Call this method 
    
    - (void)keyboardWillShow:(NSNotification *)note {
    
    
       UIButton *doneButton  = [[UIButton alloc] initWithFrame:CGRectMake(0, 163, 106, 53)];
        doneButton.adjustsImageWhenHighlighted = NO;
        [doneButton setImage:[UIImage imageNamed:@"Done.png"] forState:UIControlStateNormal];
       [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
        UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
        UIView* keyboard;
        for(int i=0; i<[tempWindow.subviews count]; i++) {
            keyboard = [tempWindow.subviews objectAtIndex:i];
    
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
                if([[keyboard description] hasPrefix:@"

提交回复
热议问题