title: How to add xib view to view controller swift 3
body: <p>I am trying to add this XIB view to my viewcontroller:</p>
  
  <pre><code>import UIKit
  
  class TranslateView: UIView {
      @IBOutlet var TranslateView: UIView!
  
      override init(frame: CGRect){
          super.init(frame: frame)
          commonInit()
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          commonInit()
      }
  
      private func commonInit(){
          Bundle.main.loadNibNamed("TranslateView", owner: self, options: nil)
          addSubview(TranslateView)
          TranslateView.frame = self.bounds
          TranslateView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
      }
  }
  </code></pre>
  
  <p>And I am loading it into my view controller here:</p>
  
  <pre><code>import UIKit
  import AVFoundation
  import Vision
  
  class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
      let captureSession = AVCaptureSession()
  
      let button: UIButton = {
          let button = UIButton()
  
          button.addTarget(self, action: #selector(ViewController.pressed(sender:)),for: .touchUpInside)
          button.backgroundColor = UIColor.clear
          button.setTitle("Translate", for: .normal)
          button.translatesAutoresizingMaskIntoConstraints = false
          return button
      }()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          setupCaptureSession()
          view.addSubview(button)
      }
  
      @objc func pressed(sender: UIButton!) {
          //add label
          button.removeFromSuperview()
  
          let headerView = Bundle.main.loadNibNamed("TranslateView", owner:
              self, options: nil)?.first as? TranslateView
          self.view.addSubview(headerView!)
          headerView?.frame = CGRect(x:0, y: 0, width: view.frame.width, height: 50.0)
      }
  </code></pre>
  
  <p>I have removed most of the code to keep this question short. I am not using a storyboard because I want to use the live cameraview as the background of my app. And by doing it in this way is the simplest. What I want to happen is that when I press the button the entire screen should be replaced with a new view which is TranslateView.xib . </p>
  
  <p>Hope someone can help. Or maybe if there is a much better simpler way then using XIB to achieve the same result let me know to.</p>
  
  <p>Please give a code example in Swift 3, not just an explanation what to do because I already know what I need to do just not how to code it.</p>