I was crawling Dribble and found the attached design. I was wondering how to do a custom navigation bar like this. I mean how create the navigation bar once and reuse it implicitly for every view controllers.
I was thinking about having a kind of root view controller and inherit for other view controllers, but I don't know how to do this.
Any idea or link will be appreachated!
Cheers.
Cyril
In older iOS versions you have to subclass UINavigationBar i.e.:
To use a custom navigation bar in your view controller, you should change a standard class name to
CustomNavigationBar
in XIB.Also, you can set the custom navigation bar programmatically:
Now
customNavigationController
has the custom navigation bar.set a custom background for the NavigationBar
then in your View Controller set custom views for left, rightBarButtons and title.
Thanks to iOS5 you are now able to customise the appearance of a UINavigationBar without having to subclass or create a category.
The following code block (put it in your applicationDidFinishLoading: method) will change the UINavigationBar for the whole application to whatever image you give it.
Note, this will ONLY work in iOS5
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav bar.png"] forBarMetrics:UIBarMetricsDefault];
However, you are also able to change the appearance of a single UINavigationBar depending on what view controller you're in by using the following code in viewDidLoad.
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav bar.png"] forBarMetrics:UIBarMetricsDefault];
The above code is solely discussing the new ways to customise the UINavigationBar appearance thanks to iOS5. However, it does not discuss the way that the buttons have been implemented.
However, adding the buttons is a different game altogether. For this, I would recommend subclassing
UINavigationBar
, and then adding in the buttons where needed through that. You could probably even get away with just a standardUINavigationBar
but customUIBarButtonItem
s that run off a particular view.For example:
I haven't tested that code so it isn't a copy/paste solution, but it gives you an idea of what needs to be done to accomplish "custom" looking UIBarButtonItems.
Good luck!
Using
Category
, add code below in your delegate file (.m)Edit:
Using
Category
is not a good way, I wrote a demo without usingCategory
, click here.You would need to make your own
UINavigationBar
subclass, and use in places where you would need a navigationController.In this custom class is where you will draw the background, buttons, text, etc.
Update
Actually, taking a closer look at this example, it appears to be a
UIToolBar
. You can assign navigation methods to the buttons likepopViewController:
etc. For the "Confirm Information" and progress indicator, you can use a label and an image. For the right button, its just a graphic.Of course, the example you provided is simply a concept, and not an actual app. But with some creativity, a few hours of coding and a few more hours of graphics design, you can achieve this same interface.
After a lot of research for one of my recent project in IOS .I decided to use subclass for customizing only navigation bar without the using UINavigationController.
I have shared a link which does a lot of custom stuff including adding background images ,text shadow etc.