2
votes

I have a UINavigationController with a UINavigationBar at the top of the screen and a UIToolbar at the bottom. I want to make the toolbar a bit taller. Here's my code:

CGRect toolbarFrame = self.navigationController.toolbar.frame;
toolbarFrame.size.height += 20;
toolbarFrame.origin.y -= 20;
self.navigationController.toolbar.frame = toolbarFrame;

[self setToolbarItems:@[myButton]];
self.navigationController.toolbarHidden = NO;

This seems like it should work and doesn't generate any errors/warnings, but the size of the toolbar stays at the defaults.

Is there a way to change the size of a UINavigationController's UIToolbar, or should I just make a custom UIToolbar for this?

1
From the docs for UINavigationController Access to this toolbar is provided solely for clients that want to present an action sheet from the toolbar. You should not modify the UIToolbar object directly.Paul.s
@Paul.s I assumed that they were referring to deeper/more functional changes, not simply messing with the appearance. Reading it again, though, you're probably right; they don't specify. Thanks :)Nathan

1 Answers

3
votes

I've tried your code and just adjust your code's sequence. It will work:

[self setToolbarItems:@[myButton]];
self.navigationController.toolbarHidden = NO;

CGRect toolbarFrame = self.navigationController.toolbar.frame;
toolbarFrame.size.height += 20;
toolbarFrame.origin.y -= 20;
self.navigationController.toolbar.frame = toolbarFrame;

I think this is because setToolbarItems will adjust the appearance of your tool bar. So you need firstly do other init-related things. Then adjust its appearance(such change its frame.)