Reputation: 3969
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!
Upvotes: 0
Views: 663
Reputation: 740
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];
Upvotes: 1