0
votes

I'm stuck at customizing the navigation bar of my app. I added the navigation controller programmatically. Indeed, in the method application:didFinishLanchingWithOptions of my app delegate, I've added and hidden a navigation bar using the following code:

self.window.rootViewController  = self.viewController;
// ListingNav previously declared as instance variable
self.ListingNav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.ListingNav.navigationBarHidden = YES;
[self.window addSubView:ListingNav.view];
[self.window makeKeyAndVisible];
return YES;

Now, I'd like to set an image as a navigation bar background, set another background image for the "back" button and add another button on the right side of the same navigation bar with its own background image too. Any idea on how to proceed ?

Thx for helping,

Stephane

4

4 Answers

2
votes

You can try:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @"ImageNameWithOutExtension"] forBarMetrics: UIBarMetricsDefault];

1
votes

Subclass UINavigationBar and override its drawRect method to draw an image.

If your UINavigationController is then created thru InterfaceBuilder, you can easily change the class of the associated UINavigationBar. If you create your UINavigationController thru code, you can use object_setClass. (this one for example)

There is a lot of questions on StackOverflow already on the exact same subject, don't hesitate to search for "NavigationController background" on the site.

1
votes

You can customize the navigation bar without hiding it. Just add these components using addSubview method.

The background image can be added as follows:

UIImageView *imageview = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"bg.png"]];
[self.navigationController.navigationBar addSubview:imageview];

[self.navigationController.navigationBar sendSubviewToBack:imageview];
[imageview release];

Since you need a custom button, you can add UIButton in the same way. Create a new UIButton with its own background and add it.

0
votes

Use This Code.....

     [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@""]]];