title: Equal height of UICollectionViewCell's and UICollectionView
body: <p>How am I supposed to set the height of the cells in UICollectionView equal to the height of whatever the collection view is? The code below doesn't work because the collection views height is not known at this point it seems since the auto layout is messing with the properties at this stage. It causes the cells height to be higher than the actual collection view.</p>
  
  <p><strong><em>I will add 300 in bounty to an answer that solves this!</em></strong></p>
  
  <pre><code>func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -&gt; CGSize {
  
         return CGSize(width: 100, height: collectionView.frame.size.height)
      }
  </code></pre>
  
  <blockquote>
    <p>2015-12-16 18:43:53.643 My-app[1055:434762] the behavior of the enter
    code hereUICollectionViewFlowLayout is not defined because: 2015-12-16
    18:43:53.643 My-app[1055:434762] the item height must be less than the
    height of the UICollectionView minus the section insets top and bottom
    values, minus the content insets top and bottom values. 2015-12-16
    18:43:53.643 My-app[1055:434762] Please check the values return by the
    delegate. 2015-12-16 18:43:53.644 My-app[1055:434762] The relevant
    UICollectionViewFlowLayout instance is , and it is attached to ; layer = ; contentOffset: {0, 0}; contentSize: {3087, 307}>
    collection view layout: .
    2015-12-16 18:43:53.644 My-app[1055:434762] Make a symbolic breakpoint
    at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the
    debugger.</p>
  </blockquote>
  
  <p><strong>Solution that works based on hannads suggestion. If there are better ways please let me know</strong></p>
  
  <p>Made a property with a property observer.</p>
  
  <pre><code>var myCollectionViewHeight: CGFloat = 0.0 {
      didSet {
          if myCollectionViewHeight != oldValue {
              myCollectionView.collectionViewLayout.invalidateLayout()
              myCollectionView.collectionViewLayout.prepareLayout()
          }
      }
  }
  </code></pre>
  
  <p>Override this method (it is called multiple times)</p>
  
  <pre><code>override func viewDidLayoutSubviews() {
      myCollectionViewHeight = myCollectionView.bounds.size.height
  }
  </code></pre>
  
  <p>Then I have this in my delegate:</p>
  
  <pre><code>func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -&gt; CGSize {            
              return CGSize(width: 100, height: myCollectionViewHeight)
      }
  </code></pre>