huix9527
12/12/2017 - 1:45 PM

IGListKit

((UICollectionViewFlowLayout *)self.layout).estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize;
- (CGSize) sizeForItemAtIndex:(NSInteger)index {
    CGFloat width = self.collectionContext.containerSize.width;
    return CGSizeMake(width, 200); // Set the height to a value that is high enough
}
- (UICollectionViewLayoutAttributes *) preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    // IMPORTANT: layout中需要有能够撑大cell底部的约束存在

    [self setNeedsLayout];
    [self layoutIfNeeded];
    
    CGSize size = [self.contentView systemLayoutSizeFittingSize:layoutAttributes.size];
    
    CGRect newFrame = layoutAttributes.frame;
    newFrame.size.height = ceilf(size.height);
    
    layoutAttributes.frame = newFrame;
    
    return layoutAttributes;
}