UICollectionView cell subviews do not resize

I ran into the same issue just now.

When using the UICollectionViewFlowLayoutDelegate method to set the cell size depending on device and device-orientation, the size would be calculated properly but subviews would not resize to fill the newly size cell. The effect was a large blank cell with small subviews that don’t fill the cell’s bounds / remain the size equal to their current value in the xib file.

I solved this by doing the following in awakeFromNib:

- (void)awakeFromNib
{
    [super awakeFromNib];

    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.contentView.translatesAutoresizingMaskIntoConstraints = YES;
}

Prior to doing this, the contentView mask was nil.

Leave a Comment