title: UICollectionViewCell dynamic height w/two dynamic labels & auto layout
body: <p>I have a UICollectionViewCell subclass that's setup with a prototype cell and constraints (every view is connected both vertically and horizontally). </p>
  
  <p>I have two labels that can vary in size, they can be either one or two lines. To that end I have set two height constraints on each label, one with a greater than or equal (16 or 20 depending on the label) and a less than or equal (32 or 40 depending on the label).</p>
  
  <p>The number of lines on the labels are set to 0. (Though I have tried a variety of settings). </p>
  
  <p>Since I've used auto layout and constraints to setup the view I've specified a width on the content view in the cell's awakeFromNib()</p>
  
  <pre><code>override func awakeFromNib() {
          NSLayoutConstraint.activate([contentView.widthAnchor.constraint(equalToConstant: 341)])
          super.awakeFromNib()
          configureBorder()
  }
  </code></pre>
  
  <p>On the collectionView's layout I've specified the automaticDimension constant for estimateItemSize &amp; itemSize</p>
  
  <pre><code>if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
      flowLayout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
      flowLayout.itemSize = UICollectionViewFlowLayoutAutomaticSize
  }
  </code></pre>
  
  <p>With the idea of using auto layout I have <em>not</em> implemented a delegate on the collection view.</p>
  
  <p>I am experiencing very inconsistent layout, some instances the cell's will appear as I'd like them to, in others the labels are truncated and in others the labels are extremely narrow and display text over three lines.</p>
  
  <p>I have tried many things, including calling 
  <code>
  .sizeToFit()
  </code>
  on each label after it's text property is set, as well as calling
  <code>
  .setNeedsDisplay()
  </code>
  before the cell returns from <code>cellForItemAt</code></p>
  
  <p>I'm wondering what is the <em>right</em> way to do this with storyboard constraints. I've worked with some of the popular answers to similar questions here on SO, though none to any real success.</p>