Custom Keyboard InputAccessoryView not visible in iOS 11

前端 未结 7 1987
攒了一身酷
攒了一身酷 2021-02-18 21:30

I have implemented Custom input accessory view it was working fine till iOS 10.3.1. But it\'s not visible in iOS 11 beta.

Have anyone experience this issue?

7条回答
  •  太阳男子
    2021-02-18 22:17

    To avoid the inputAccessoryView issue in iOS 11 for UITextField and UITextView, just use the following code:

    UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    
    self.monthPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    
        self.monthPickerView.backgroundColor = [UIColor whiteColor];
    
        self.monthPickerView.delegate = self;
    
        self.monthPickerView.dataSource = self;
    [inputView addSubview:self.monthPickerView];
    
        cell.monthTextField.inputView = inputView ;
    
    self.monthTextField.inputAccessoryView = [self doneButtonAccessoryView];
    
    
    // doneButtonAccessoryView Method
    
    
    -(UIToolbar*)doneButtonAccessoryView
    {
    
        UIToolbar *kbToolbar = [[UIToolbar alloc] init];
        [kbToolbar sizeToFit];
        [kbToolbar setBarTintColor:[UIColor whiteColor]];
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                       style:UIBarButtonItemStyleDone target:self
                                                                      action:@selector(doneClicked)];
    
        UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
                                                                         style:UIBarButtonItemStyleDone target:self
                                                                        action:@selector(cancelClicked)];
        NSDictionary *attrDict;
    
        attrDict = [NSDictionary dictionaryWithObjectsAndKeys:
                    [UIFont fontWithName:@"Helvetica-Bold" size:16.0], NSFontAttributeName, nil];
     [doneButton setTitleTextAttributes:attrDict forState:UIControlStateNormal];
        UIBarButtonItem *flexWidth = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                                   target:self action:nil];
    
        [kbToolbar setItems:[NSArray arrayWithObjects:cancelButton,flexWidth, doneButton, nil]];
        return kbToolbar;
    }
    

提交回复
热议问题