Search code examples
objective-cuinavigationcontrolleruiimage

how to set a navigation controllers background


how do I set an image to be a background of a Navigation controller, like the view, not the bar.

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

I tried using that to set it, and even went as far as to change the property to UIViewControllers, but after that. it just spits errors.


Solution

  • In Your AppDelegate in - (void) applicationDidFinishLaunching:(UIApplication *)application method add the following.

    [[UINavigationBar appearance] setBackgroundImage:YourImage forBarMetrics:UIBarMetricsDefault];
    

    In Swift

    let navBackgroundImage:UIImage! = UIImage(named: "backgroundNB.png")
    UINavigationBar.appearance().setBackgroundImage(navBackgroundImage,  forBarMetrics: .Default)