jbiser361
jbiser361

Reputation: 987

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.

Upvotes: 1

Views: 54

Answers (2)

Atmaram
Atmaram

Reputation: 634

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)

Upvotes: 1

user12039958
user12039958

Reputation:

Why do you want to change the background of the Navigation Controller? It handles the transitioning between two controllers that you want to navigate between, it in of itself isn't used as a controller - it's effectively just the navigation bar component. If you want to change the background, change it on the initial and final views.

Upvotes: 0

Related Questions