title: How to add xib subviews with dynamic height to UIView
body: <p>It should be easy to do and it's very easy in android(with LinearLayout) but I can't figure out how to do it in ios.</p>
  
  <p>I have UIView into which I want to add some dynamic height subviews. Subview is loaded from xib file and contains 2 UILabels with dynamic height.</p>
  
  <pre><code>class Subview: UIView {
  
      @IBOutlet var contentView: UIView!
  
      @IBOutlet weak var title: UILabel!
      @IBOutlet weak var desc: UILabel!
  
  
      override init(frame: CGRect) {
          super.init(frame: frame)
          self.commonInit()
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          self.commonInit()
      }
  
      fileprivate func commonInit() {
          Bundle.main.loadNibNamed("Subview", owner: self, options: nil)
          addSubview(contentView)
          self.contentView.frame = self.bounds
          self.contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
      }
  
  }
  </code></pre>
  
  <p>and subview is added like this</p>
  
  <pre><code>var containerView: UIView
  
  func setupView() {
  
      let subview1 = Subview()
      subview1.title = "Some title"
      subview1.desc = "Some very long description"
  
      self.containerView.addSubview(subview1)
  
  }
  </code></pre>
  
  <p>Issue is that in this case, subview is not displayed.
  If I add </p>
  
  <pre><code>subview1.frame = CGSize(width: self.bounds.width, height: 100)
  </code></pre>
  
  <p>subview is displayed but height 100 is not correct</p>
  
  <p>If I try to calculate subview size</p>
  
  <pre><code>let measuredSize = subview1.sizeThatFits(CGSize(width: self.bounds.width, height: CGFloat(MAXFLOAT)))
  </code></pre>
  
  <p>measured width and size is 0.</p>
  
  <p>Any idea what I am doing wrong here? Thanks!</p>
  
  <p>Edit: This is my subview xib file with constraints
  <a href="https://i.stack.imgur.com/633EK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/633EK.png" alt="enter image description here"></a></p>