title: Set UINavigationBar background image in ViewController
body: <p>I am able to set the background for my navbar to a custom image in the app delegate didFinishLaunchingWithOptions method with this code:</p>
  
  <pre><code>UIImage *navBarImage;
  navBarImage = [UIImage imageNamed:@"navbar.png"];
  
  [[UINavigationBar appearance] setBackgroundImage: navBarImage forBarMetrics:UIBarMetricsDefault];
  </code></pre>
  
  <p>I'm trying to add an option in my app to change the background image of the navbar when a switch is toggled, however it does not seem to work. Is it only possible to set the background image when the app launches? How can I do this after the app has already launched?</p>
  
  <p>This is the code I have:</p>
  
  <pre><code>- (void) switchChanged:(id)sender {
      UISwitch* switchView = sender;
  
          if (switchView.isOn) {
              UIImage *navBarImage = [UIImage imageNamed:@"black_nav.png"];
              [[UINavigationBar appearance] setBackgroundImage: navBarImage forBarMetrics:UIBarMetricsDefault];
          }
          else {
              UIImage *navBarImage = [UIImage imageNamed:@"white_nav.png"];
              [[UINavigationBar appearance] setBackgroundImage: navBarImage forBarMetrics:UIBarMetricsDefault];
          }
  }
  </code></pre>