简体   繁体   中英

iOS: Toolbar above keyboard

I have a UIToolBar, and a TextBox. When I select the TextBox, the keyboard appears and the toolbar disappears (because the keyboard is in front of the toolbar). I want to do like status update of facebook, when you select the TextBox, the Toolbar is above the keyboard:

状态Facebook

How can I do this?

Text fields have this property called inputAccessoryView , that allows you to put any view on top of the keyboard. It looks like your case is pretty simple, otherwise, if you cannot use accessory view, you can look at dozens of implementations here .

First create a UIToolbar that has your desired buttons etc...

Then all you need to do is on

 - (void)textViewDidBeginEditing:(UITextView *)textView
{
    toolBar *tb = [[myToolbar alloc] init]
    [textView setInputAccessoryView:tb];
}

if Not try this using IB Maybe (not tested)

myToolbarClass* myToolbar = [[[NSBundle mainBundle] 
loadNibNamed:@"toolbarNib" owner:self options:nil] objectAtIndex:0]
[textView setInputAccessoryView:myToolbar];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM