Adding image to navigation bar

In your case, this solution found in another answer would work well.

With the “CustomImage” category added to UINavigationBar,
you can then just call:

UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"yourNavBarBackground.png"];
[navBar setBackgroundImage:image];

This code should go in the method

- (void)viewWillAppear:(BOOL)animated

of the view controller where you want to have the custom image.
And, in that case you should better call:

[navBar clearBackgroundImage]; // Clear any previously added background image

before setBackgroundImage (otherwise it will be added multiple times…)

Leave a Comment

tech