title: Swift Custom Navigation Controller Class
body: <p>Everyone who reads it, hello and thank you. I am writing an application like Viber or WhatsApp for iOS devices using Xcode 8.2.1 and Swift 3.0. I have a problem: I want my app has a navigation controller but not a simple one, I want it to be a custom one. There is a print screen from WhatsApp to be understanding, what I am trying to achieve:</p>
  
  <p><a href="https://i.stack.imgur.com/pqBIol.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/pqBIol.jpg" alt="Screenshot of WhatsApp chat with somebody"></a></p>
  
  <p>As we can see, this navigation controller has 3 buttons, label and image with avatar. I also want to change my color to green one. Due to do this I have created class:</p>
  
  <pre><code>import UIKit
  
  class CustomNavigationController: UINavigationController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.navigationBar.barTintColor = UIColor.green
  
  
          let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 39, height: 39))
          imageView.contentMode = .scaleAspectFit
          let image = UIImage(named: "logo")
          imageView.image = image
          navigationItem.titleView = imageView
  
  
      }
  }
  </code></pre>
  
  <p>And it gives this result:
  <a href="https://i.stack.imgur.com/X9HHnl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/X9HHnl.png" alt="enter image description here"></a>
  As you can see it is without picture. I know that if I add this code:</p>
  
  <pre><code>        let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 39, height: 39))
          imageView.contentMode = .scaleAspectFit
          let image = UIImage(named: "logo")
          imageView.image = image
          navigationItem.titleView = imageView
  </code></pre>
  
  <p>to ViewController, image with logo will appear but I want complete class which I will connect somewhere (for example, in Interface Builder) and it will make a beautiful Navigation Controller with buttons, images and etc. Moreover, I can create a different class with another Navigation Controller and connect it to different screens, on which, for example, I will not need images, only buttons. So question is: how to make custom Navigation Controller class?</p>
  
  <p>I will be really glad and thankful for any help, Thank You!</p>