Search code examples
iphoneiphone-softkeyboard

display keyboard with button list on the top


I hope to push keyboard with button list on the top of the keyboard. Please refer to the image

enter image description here

Is it possible?


Solution

  • you need to add a toolbar. Here is an example I used for an action sheet - you can make the modifications for the keyboard easily:

      //DEFINING TOOL BAR 
    UIToolbar * keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    keyboardToolbar.barStyle = UIBarStyleBlackOpaque;
    [keyboardToolbar sizeToFit];    
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];
    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissKeyboard:)];
    [barItems addObject:doneBtn];
    [keyboardToolbar setItems:barItems animated:YES];
    [keyboard addSubview:keyboardToolbar]; 
    

    You can obviously add more items to the UIToolBar for "Next", "Previous", etc.