title: Auto Layout: can't get the frame size of UICollectionViewCell subViews
body: <p>I have a custom UICollectionViewCell subclass (<code>MyCell</code>), its interface is setup in Interface Builder using Auto Layout. The cell has an image view and a label.</p>
  
  <p>Now, when I configure the cell, I need to know the width and the height of the image view. Sounds pretty simple, but it looks like it's impossible.</p>
  
  <p>In my view controller:</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
      MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
      cell.itemNumber = indexPath.item;
      return cell;
  }
  </code></pre>
  
  <p>In my cell subclass I am using my property's setter to customize the cell:</p>
  
  <pre><code>- (void)setItemNumber:(NSInteger)itemNumber {
      _itemNumber = itemNumber;
      self.label.text = [NSString stringWithFormat:@"%i", self.itemNumber];
  
      // In my actual project I need to know the image view's width and hight to request an image
      // of the right size from a server. Sadly, the frame is always {{0, 0}, {0, 0}}
      // (same for the bounds)
      NSLog(@"%@", NSStringFromCGRect(self.myImageView.frame));
  }
  </code></pre>
  
  <p>A full example project can be found at <a href="https://github.com/kevinrenskers/CollectionViewAutoLayoutTest" rel="noreferrer">https://github.com/kevinrenskers/CollectionViewAutoLayoutTest</a>.</p>
  
  <p>So the problem is this: I need to know the image view's size because I need to ask a server to generate an image of the correct size. And the image view's size is {0,0}..</p>
  
  <p>I've tried to do the customizing in the <code>-layoutSubviews</code> method too:</p>
  
  <pre><code>- (void)setItemNumber:(NSInteger)itemNumber {
      _itemNumber = itemNumber;
  }
  
  - (void)layoutSubviews {
      if (self.myImageView.frame.size.height) {
          self.label.text = [NSString stringWithFormat:@"%i", self.itemNumber];
          NSLog(@"%@", NSStringFromCGRect(self.myImageView.frame));
      }
  }
  </code></pre>
  
  <p>Sadly, this is even more messed up. The method is called twice, first the frame is {{0, 0}, {0, 0}} and then the frame is set correctly. Thus the if statement that checks for the height. Once you start scrolling though, the wrong labels are showed for the wrong cells. I don't understand what's going on here.</p>
  
  <p>The problem probably makes more sense when you try it in the <a href="https://github.com/kevinrenskers/CollectionViewAutoLayoutTest" rel="noreferrer">example project</a>.</p>
  
  <p>Setting width- and height constraints and making IBOutlets to it sounds like a great option, but sadly the cells don't have a fixed size and the image needs to shrink and grow with the cell. Removing auto layout isn't an option either.</p>