Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad title bars. Navbars or toolbars?

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?

like image 776
Alex Wayne Avatar asked Apr 10 '10 02:04

Alex Wayne


3 Answers

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.

like image 24
Brad Larson Avatar answered Oct 31 '22 19:10

Brad Larson


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.

like image 60
igul222 Avatar answered Oct 31 '22 21:10

igul222


You can also hide navigation controller with
self.navigationController.navigationBarHidden = YES; . But at same time, add a back button on the left of toolbar, which will call popviewcontrollers

like image 2
Jexcy Avatar answered Oct 31 '22 21:10

Jexcy