在键盘上添加UIToolBar,隐藏键盘

- (void) addToolBarlOnKeyboard {

    

    //在键盘上添加toolbar工具条  点击工具条中的按钮回收键盘

    UIToolbar * toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];

    [toolBar setBarStyle:UIBarStyleDefault];

    UIBarButtonItem * btnSpace = [[UIBarButtonItem  alloc]initWithBarButtonSystemItem:                                        UIBarButtonSystemItemFlexibleSpace target:self action:nil];

    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"隐藏键盘"            style:UIBarButtonItemStyleDone  target:self action:@selector(takebackkeyboard)];

    NSArray * buttonsArray = [NSArray arrayWithObjects:btnSpace,doneButton,nil];

    //关键的代码,不写的话不会在键盘上面显示工具条

 [_commentView setInputAccessoryView:toolBar];     

    [toolBar setItems:buttonsArray];

    [toolBar release];

    [btnSpace release];

    [doneButton release];

    

}



- (void)takebackkeyboard {

    [_commentView resignFirstResponder];    

}

 

你可能感兴趣的:(toolbar)