Add UIToolBar above keyboard


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. - (void)textFieldDidBeginEditing:(UITextField *)textField
  2. {
  3.  
  4. // add toolbar above keyboard
  5. UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
  6. toolBar.barStyle = UIBarStyleBlackTranslucent;
  7.  
  8. // done button
  9. UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:@"Fechar"
  10. style:UIBarButtonItemStyleBordered
  11. target:self action:@selector(closeKeyboard)];
  12.  
  13. UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
  14. target:nil
  15. action:nil];
  16.  
  17. toolBar.items = [NSArray arrayWithObjects:space, done, nil];
  18. [space release];
  19. [done release];
  20.  
  21. textField.inputAccessoryView = toolBar;
  22. [toolBar release];
  23.  
  24. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.