title: XIB view not showing with correct layout [iOS Swift]
body: <p>I'm trying to make a custom alert view and facing some issues with the fact that the displayed view is cutting the bottom half of the view (Images below)</p>
  
  <p><strong>How it's being displayed:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/6Sp3U.png" alt="How it&#39;s being displayed"></p>
  
  <p><strong>Desired Output:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/H9Po4.png" alt="Desired output"></p>
  
  <p>So basically, I have a XIB called CustomAlertView supported by a class of same name with init as follows:</p>
  
  <pre><code>    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("CustomAlertView", owner: self, options: nil)
      contentView.frame = self.bounds
      contentView.translatesAutoresizingMaskIntoConstraints = true
      addSubview(contentView)
      //contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  
  }
  </code></pre>
  
  <p>I have another class that is responsible for creating an alert, CustomAlert, using the customAlertView. This CustomAlert class is creating the <strong>backgroundView</strong> and <strong>dialogView</strong>( which I'm trying to add my customAlertView to it) with the following code:</p>
  
  <pre><code>func initialize(title:String, description:String){
      dialogView.clipsToBounds = true
  
      backgroundView.frame = frame
      backgroundView.backgroundColor = UIColor.black
      backgroundView.alpha = 0.6
      backgroundView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTappedOnBackgroundView)))
      addSubview(backgroundView)
  
      dialogView.frame.origin = CGPoint(x: 0, y: 0)
      dialogView.frame.size = CGSize(width: frame.width-32, height: frame.height/3)
  
      dialogView.backgroundColor = UIColor.white
      dialogView.layer.cornerRadius = 6
  
      let alertView = CustomAlertView.init(frame: self.bounds)
      alertView.titleLabel.text = title
      alertView.descriptionLabel.text = description
      alertView.cancelButton.backgroundColor = UIColor.brown
  
      dialogView.addSubview(alertView)
  
  
      addSubview(dialogView)
  }
  </code></pre>
  
  <p>I believe that I'm making a confusion with the frames and bounds but couldn't find a solution.</p>
  
  <p>I'd like the desired output to be placed perfectly inside the dialogView.</p>
  
  <p>EDIT</p>
  
  <p>Code for my .show function in CustomAlert</p>
  
  <pre><code>func show(animated:Bool){
  
      self.backgroundView.alpha = 0
      self.dialogView.center = CGPoint(x: self.center.x, y: self.frame.height + self.dialogView.frame.height/2)
      UIApplication.shared.delegate?.window??.rootViewController?.view.addSubview(self)
      if animated {
          UIView.animate(withDuration: 0.33, animations: {
              self.backgroundView.alpha = 0.66
          })
          UIView.animate(withDuration: 0.33, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: UIViewAnimationOptions(rawValue: 0), animations: {
              self.dialogView.center  = self.center
          }, completion: { (completed) in
  
          })
      }else{
          self.backgroundView.alpha = 0.66
          self.dialogView.center  = self.center
      }
  }
  </code></pre>
  
  <p>Github link <a href="https://github.com/raphahenrique/poc-alertview-ios" rel="nofollow noreferrer">git-alert-view</a></p>