0
votes

I have a storyboard based app with a navigation controller as the initial view controller.

I would like to set the background for the navigation bar to an image using the setBackgroundImage:forBarMetrics: method, but I am unsure of where to call it.

I could subclass the UINavigationController and use the viewDidLoad method to call it, but subclassing UINavigationController is discouraged. I guess I should subclass UINavigationBar and override some initialisation method?

Thanks,

Steve

1

1 Answers

3
votes

I've worked this one out myself. I wanted all navigation bars throughout the app to have the custom background, so the easiest way to do this seems to be using the appearance proxy for the navigation bar:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar.png"]

This will set the background image of all navigation bars to be "title_bar.png".

It would seem a good place to do this sort of customisation is in the:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

method in your application delegate.