title: UINavigationBar transition between color and transparent - bug [iOS 11]
body: <p>I've discovered a weird behavior on iOS 11 when I push <code>UIViewController</code> and change the <code>UINavigationBar</code> color to transparent. Important thing is that I'm using <code>largeTitles</code>.</p>
  
  <ol>
  <li><p>I want to change red color of the navigation bar to transparent and this works fine.</p></li>
  <li><p>However, if I tap on backButton, disable transparent style and red color style again something bad happened. NavigationBar on the ViewController is not red but still transparent.</p></li>
  <li><p>As @Menoor Ranpura suggest I add another line which sets also a <code>backgroundColor</code> of view in <code>UIViewController</code> - and this is fine workaround when you set the same color like on <code>UINavigationBar</code>. However, it's not the solution for the problem because the large part of the navigation bar is still transparent. You can see it when you set the different color for a background. For example, I set the yellow. You can see the example here:</p></li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/UenjC.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UenjC.gif" alt="enter image description here"></a></p>
  
  <h1>Question</h1>
  
  <p>How to properly change the navigation bar color <strong>from transparent</strong> to <strong>red again</strong>, when the <code>prefersLargeTitles</code> is set to <code>true</code>?</p>
  
  <h1>Code</h1>
  
  <pre><code>class ExampleTableTableViewController: UITableViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          tableView.register(UITableViewCell.self, forCellReuseIdentifier: "reuseID")
          navigationController?.navigationBar.redNavigationBar()
          title = "Red NavBar"
      }
  
      override func viewDidAppear(_ animated: Bool) {
          super.viewDidAppear(animated)
          view.backgroundColor = .yellow
          navigationController?.navigationBar.redNavigationBar()
      }
  }
  
   //Transparent Navigation bar controller
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          title = "Transparent NavBar"
          view.backgroundColor = .blue
          self.navigationController?.navigationBar.prefersLargeTitles = true
      }
  
      override func viewWillAppear(_ animated: Bool) {
          self.navigationController?.navigationBar.transparentNavigationBar()
      }
  
  }
  extension UINavigationBar {
      func redNavigationBar() {
          setBackgroundImage(nil, for: .default)
          shadowImage = nil
  
  
          prefersLargeTitles = true
          tintColor = .white
          largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
          titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
          barTintColor = .red
      }
  
      func transparentNavigationBar() {
          setBackgroundImage(UIImage(), for: .default)
          shadowImage = UIImage()
      }
  }
  </code></pre>
  
  <h2>Some tips that I've already tested:</h2>
  
  <ul>
  <li>Everything works fine when <code>prefersLargeTitles</code> is set to <code>false</code></li>
  <li>Everything works fine when <code>prefersLargeTitles</code> is set to <code>true</code>, but <code>navigationBar</code> changes are between non transparent colors. For example, if changing between green &lt;-> yellow</li>
  <li>I don't want to set <code>backgroundColor</code> on view. It's not an solution but kind of a workaround for this. </li>
  </ul>
  
  <p>Here you can see a screen from XCode:</p>
  
  <p><a href="https://i.stack.imgur.com/4lInn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4lInn.png" alt="enter image description here"></a></p>
  
  <p>Interesting fact is that, there is something called: <code>_UINavigationBarLargeTitleView</code> which is transparent. <strong>How to access it?</strong></p>
  
  <h3>Related problems:</h3>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/2315862/make-uinavigationbar-transparent">Make UINavigationBar transparent</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/40243112/uinavigationbar-change-colors-on-push/40250912">UINavigationBar change colors on push</a></p></li>
  </ul>
  
  <p><strong>You can find example project here: <a href="https://github.com/kamwysoc/LargeTitlesNavigationBarTransition" rel="nofollow noreferrer">https://github.com/kamwysoc/LargeTitlesNavigationBarTransition</a></strong></p>
  
  <hr>
  
  <h1>UPDATE referring to @Menoor Ranpura answer</h1>
  
  <p>Code that @Menoor Ranpura suggest is a kind of a workaround. It's not a solution to set the same <code>backgroundColor</code> on <code>UIViewController</code> view like <code>UINavigationBar</code> has. However, I go a bit further and I change the color for a different than <code>UINavigationBar</code> controller has. And as you can see on above gif, when the <code>largeTitle</code> appears, the navigation bar becomes yellow - which means that is transparent - because we're able to see the yellow background of view. </p>