Context
I've got a UIButton that I'm adding, method is below:
[self.view addSubview:[self returnCustomSubmitButton]];
I don't add the toolbar as a subview, I set the ViewControllers navigationController property toolBarHidden to NO. - [self.navigationController setToolbarHidden:NO animated:NO];
at viewWill apear
Extra Detail
The reason I'm doing this is because I want to create something like the toolbar (NOTE: This is a UITabBar, but I'm looking for the same shape) below - so I'm adding a toolbar and then adding a UIButton to the viewControllers view and using the toolbars coordinates to position the UIButton
I've tried to follow along to this (NOTE: Again this is for a UITabBar), but struggling: http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/
Problem
The UIButton is hidden behing the UIToolbar (I want it to sit on top of the toolbar).
Questions
Update
After lots of attempts at fixing this, is this something to do with the fact I'm using UINavigationController and the fact that I'm adding a UIButton to the "Custom Content" area and the nav toolbar sits on top of that whatever I do. See below:
Although I think that the best solution is to create your UIToolbar
programmatically and then create and add any custom UIBarButtonItem
s, here is a possible solution to your problem:
(Note: Apple says that you must not try to modify UINavigationController
's default toolbar, so if you're planning to do so try the above suggestion)
- (void)viewDidLoad
{
[super viewDidLoad];
// Show the default toolbar
[self.navigationController setToolbarHidden:NO];
// Create a UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"btn"] forState:UIControlStateNormal];
[button sizeToFit];
// Add your targets/actions
[button addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];
// Position the button
// I am sure that there must be
// a million better ways to do this
// (it's here just to illustrate the point)
button.center = self.navigationController.toolbar.center;
CGRect frame = button.frame;
frame.origin.y = CGRectGetMaxY([UIScreen mainScreen].bounds) - button.frame.size.height;
button.frame = frame;
// Here is the tricky part. Toolbar is not part
// of your controller's view hierarchy, it belongs
// to the navigation controller. So add the button there
[self.navigationController.view addSubview:button];
}