0
votes

I have the following code in viewWillAppear in my view controller.

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    UIImage *image = [UIImage imageNamed:@"navbar.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [self.navigationController.navigationBar addSubview:imageView];
}

How do I clear the navigation bar background image that is already there before adding a new nav bar image as in the code above?

Also, how can I set a different navigation bar background image for each different controller the most efficient way possible? thanks!

1
use UIAppearance for setting different navbar styles. see stackoverflow.com/questions/8736171/…Daij-Djan

1 Answers

1
votes

In your viewWillAppear method, use the following call to set the background image of the navigation bar.

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

If your app supports landscape as well, you'll also need to set the background image for the landscape navigation bar with a different height:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_landscape.png"] forBarMetrics:UIBarMetricsLandscapePhone];