user2376637
user2376637

Reputation: 1

How to create custom navigation bar programmatically?

I'm developer in objective c and I need help with with set custom navigation bar on navigation controller programmatically I don't use story board or xib.

Upvotes: 0

Views: 3325

Answers (2)

Bonnie
Bonnie

Reputation: 4953

you can use this, if your targeting iOS 5 and above

[MyNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"customNavBar.png"] forBarMetrics:UIBarMetricsDefault];

or

[[MyNavigationController.navigationBar appearance] setBackgroundImage:navBackground forBarMetrics:UIBarMetricsDefault];

you may need to add custom NavBar Buttons.

also have a look at the Answers here.

Upvotes: 1

Marcin Kuptel
Marcin Kuptel

Reputation: 2664

If you want more than just customizing appearance, then you can:

  1. Create a subclass of UIView (this will be your custom navigation bar)
  2. Create a custom view controller container that will contain an instance of UINavigationController
  3. Make the instance of UINavigationController not display its navigation bar
  4. Add your custom navigation bar and navigation controller's view as subviews of your custom view controller container (also add your instance of UINavigationController as a child controller of your custom view controller container)
  5. Add methods for popping and pushing view controllers to your custom view controller container

This way you have full control over your custom navigation bar. You can read about view controller containment in the documentation for UIViewController.

Upvotes: 0

Related Questions