设置键盘顶部显示的工具条

- (void)createKeyboardTool
{
    keyboardTool = [[UIToolbar alloc] initWithFrame: CGRectMake(kZero, kZero, kScreenW, 44.0f)];
    NSMutableArray *myToolBarItems = [NSMutableArray array];

  //创建键盘工具条上面的按钮,并设置点击事件 UIBarButtonItem
*cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(cancelAction)]; UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(saveAction)]; UIBarButtonItem *saveBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(saveAction)]; [myToolBarItems addObject:cancelBtn]; [myToolBarItems addObject:space]; [myToolBarItems addObject:saveBtn]; keyboardTool.items = myToolBarItems; }
    //inputAccessoryView:设置键盘顶部显示的工具条;inputView:自定义键盘
commentTextView = [[UITextView alloc]initWithFrame:CGRectMake(kZero, kZero, kScreenW, 200)]; [commentTextView becomeFirstResponder]; commentTextView.inputAccessoryView = keyboardTool;
原文地址:https://www.cnblogs.com/hw140430/p/3889557.html