Custom Keyboard InputAccessoryView not visible in iOS 11

前端 未结 7 2008
攒了一身酷
攒了一身酷 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 21:58

    UIToolBar is broken in iOS 11. But you can get the same thing done using UIView as inputAccessoryView. Sample code snippet here:

    CGFloat width = [[UIScreen mainScreen] bounds].size.width;
    UIView* toolBar = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f, width, 44.0f)];
    toolBar.backgroundColor = [UIColor colorWithRed:0.97f  green:0.97f blue:0.97f alpha:1.0f];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0 , 0.0f, width, 44.0f)];
    [titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:13]];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setTextColor:[UIColor redColor]];
    [titleLabel setText:@"Title"];
    [titleLabel setTextAlignment:NSTextAlignmentLeft];
    [toolBar addSubview:titleLabel];
    
    UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [doneBtn setTitle:@"Done" forState:UIControlStateNormal];
    doneBtn.tintColor = [UIColor colorWithRed:(float)179/255 green:(float)27/255 blue:(float)163/255 alpha:1];
    [doneBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
    [doneBtn addTarget:self action:@selector(btnTxtDoneAction) forControlEvents:UIControlEventTouchUpInside];
    [doneBtn setFrame:CGRectMake(width-70, 6, 50, 32)];
    [toolBar addSubview:doneBtn];
    
    [toolBar sizeToFit];
    
    txtMessageView.inputAccessoryView = toolBar;
    

    Hope this help..:)

提交回复
热议问题