title: how to set the image position and size of image that inserted in navigation bar?
body: <p>actually I don't know the correct way how to make an image inside the navigation bar like this, either using navigation controller or by using custom view by myself</p>
  
  <p><a href="https://i.stack.imgur.com/f8mkD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f8mkD.png" alt="enter image description here"></a></p>
  
  <p>I need to insert these 2 image as bar button and image title
  <a href="https://i.stack.imgur.com/BYIvz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BYIvz.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/fg2ON.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fg2ON.png" alt="enter image description here"></a></p>
  
  <p>so I tried to use navigation controller and insert an image in <code>viewDidLoad</code> like the code below:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // insert image title
          let aspectRatio : CGFloat = 0.25
          let widthOfImageHeader = view.frame.width * 0.5
          let heightOfImageHeader = widthOfImageHeader * aspectRatio
  
          let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: widthOfImageHeader, height: heightOfImageHeader))
          imageView.contentMode = .scaleAspectFit
          let image = UIImage(named: "testImage2")
          imageView.image = image
          navigationItem.titleView = imageView
  
  
           // set bar button image
           //create a new button
           let button = UIButton(type: .custom)
           //set image for button
           button.setImage(UIImage(named: "hamburgerIcon"), for: .normal)
  
           //set frame
           button.frame = CGRect(x: 0, y: 0, width: 53, height: 51)
  
           let barButton = UIBarButtonItem(customView: button)
            //assign button to navigationbar
            self.navigationItem.leftBarButtonItem = barButton
      }
  
  
  }
  </code></pre>
  
  <p>but the result is like the image below:
  <a href="https://i.stack.imgur.com/U8nE6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U8nE6.png" alt="enter image description here"></a></p>
  
  <p>the position of image title is not exactly in the center for iPhone 5s and bar button seems a little bit off in the right.</p>
  
  <p>and if I assign the image right bar button, using</p>
  
  <pre><code>    /
  
  /create a left button
          let button = UIButton(type: .custom)
          //set image for button
          button.setImage(UIImage(named: "hamburgerIcon"), for: .normal)
  
          //set frame
          button.frame = CGRect(x: 0, y: 0, width: 53, height: 51)
  
          let barButton = UIBarButtonItem(customView: button)
          //assign button to navigationbar
          self.navigationItem.leftBarButtonItem = barButton
  
          //create a right button
          let button2 = UIButton(type: .custom)
          //set image for button
          button2.setImage(UIImage(named: "backButton"), for: .normal)
  
          //set frame
          button2.frame = CGRect(x: 0, y: 0, width: 53, height: 51)
  
          let barRightButton = UIBarButtonItem(customView: button)
          //assign button to navigationbar
          self.navigationItem.rightBarButtonItem = barRightButton
  </code></pre>
  
  <p>the result is even weirder</p>
  
  <p><a href="https://i.stack.imgur.com/5TamG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5TamG.png" alt="enter image description here"></a></p>
  
  <p>one of the button dissapears, the hamburger icon that should be on the left, now in the right</p>
  
  <p>it will be far easier if I use custom view, but...is it weird if I use custom view that use like navigation bar? I am new in iOS Developer. Thanks in advance</p>