title: How to programmatically add/remove an image to navigation bar title in Swift 3/Xcode
body: <p>So I currently have a menu bar open and close on the left side of the app, and I want a certain image to appear on the navigation bar title when I open the menu. Below is my function for opening and closing the menu.</p>
  
  <pre><code>@IBAction func openMenu(_ sender: Any) {
  
      if (menuShowing) {
          self.navigationController?.navigationBar.barTintColor = UIColor(red:0.00, green:0.20, blue:0.63, alpha:1.0)
          navigationItem.leftBarButtonItem?.tintColor = UIColor.white
          navigationItem.titleView = ""
          leadingConstraint.constant = -240
          shadowLeadingConstraint.constant = -250
          UIView.animate(withDuration: 0.6, animations: {
              self.view.layoutIfNeeded()
          })
  
      }
      else {
          self.navigationController?.navigationBar.barTintColor = UIColor.white
          navigationItem.leftBarButtonItem?.tintColor = UIColor(red:0.00, green:0.20, blue:0.63, alpha:1.0)
  
          let image = UIImage(named: "MenuBarTransparent")
          navigationItem.titleView = UIImageView(image: image)
          navigationItem.titleView?.frame=CGRect(x:10, y:0, width:30, height:360)
  
          leadingConstraint.constant = 0
          shadowLeadingConstraint.constant = 0
          UIView.animate(withDuration: 0.3, animations: {
              self.view.layoutIfNeeded()
          })
      }
      menuShowing = !menuShowing
  }
  </code></pre>
  
  <p>This portion of code in the above function makes the image appear when I want it to, but manipulating the x and y-coordinate has no effect whatsoever so I can't center the image correctly:</p>
  
  <pre><code>let image = UIImage(named: "MenuBarTransparent")
          navigationItem.titleView = UIImageView(image: image)
          navigationItem.titleView?.frame=CGRect(x:10, y:0, width:30,  height:360)
  </code></pre>
  
  <p>Also, this portion of code from above does not let me delete the image from the nav bar title whenever I close the menu again, it says "Cannot assign value of type 'String' to type 'UIView?':</p>
  
  <pre><code>navigationItem.titleView = ""
  </code></pre>
  
  <p>Thanks in advance for any help.</p>