views:

1300

answers:

2

I see a bunch of apps for iPad with really cool title bars. These seem to be a combination of a navigation bar and a toolbar. They usually have a back button and a title as well as men other buttons. And a navbar only supports a left item, a right item and and title view. And the toolbar does not really support back buttons or titles.

So how do I implement these rich navbars with many buttons on my UINavigationController driven application?

+3  A: 

You can get this effect by putting a UIToolbar in your UINavigationItem like so:

self.navigationItem.title = @"My Title";    


UIToolbar *tb = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
tb.items = [NSArray arrayWithObjects:button1,button2,button3,nil];

UIBarButtonItem *tbItem = [[UIBarButtonItem alloc] initWithCustomView:tb];
self.navigationItem.rightBarButtonItem = tbItem;

[tbItem release];
[tb release];

source: this blog, via google.

igul222
I found this useful. The only drawback I found is that you can't really have a translucent navigation bar, since the translucent toolbar draws on top and you get something almost entirely opaque in that region.
David Dunham
Hmmm... you might be able to remove the UIToolbar's background by doing a little poking around the view hierarchy...
igul222
+1  A: 

Most of these applications are using a UISplitViewController at their base level, with a UIToolbar at the top of the larger right-hand detail view for the split view controller. The left-hand view is provided by a UINavigationController. This gives you the navigation controls in the toolbar on the left, as well as multiple toolbar buttons on the right. These are separate bars at the top of the screen, but they can appear to merge together if the same style is used for both.

For an example of how to do this, you can download the source code to my universal iPhone / iPad application Molecules and look inside the SLSMoleculeAppDelegate, where I construct the split view controller in code, and the SLSMoleculeiPadRootViewController, where I set up the toolbar and its items.

Brad Larson