2015-01-29

iOS display bottom bar with inputAccessoryView

Views: 7115 | Add Comments

You can display a navigation toolbar at the bottom of the screen, the bottom bar is managed by the navigation controller.

[self.navigationController setToolbarHidden:NO];
[self.navigationController.toolbar setBarStyle:UIBarStyleDefault];
self.navigationController.toolbar.translucent = NO;

But there are some bad sides of this approach:

  • you are not able to change its height(not easily)
  • the bottom bar will be covered by keyboard

We can also implement a custom bar with inputAccessoryView, with this approach, there are many good sides:

  • the bottom bar is to follow the keyboard as the keyboard appears and disappears
  • it can be any type of UIView: UIButton, UILabel, and custom UIView subclass
  • height of the bar can be specified

Put this code in one of your view controller:

- (BOOL)canBecomeFirstResponder{
	return YES;
}

- (UIView *)inputAccessoryView{
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 30)];
	label.text = @"Bottom Bar...";
	label.backgroundColor = [UIColor yellowColor];
	return label;
}

Here is the screen shot:

Posted by ideawu at 2015-01-29 14:18:51 Tags:

Leave a Comment