ios – How to make UICollectionview cell height dynamic?

1) Override collectionflowlayout delegate method

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSizeMake(50, 50); //(width,hight)
}

2) In above method, Calculate the height of textview which contains dynamic length and add that value in your fixed height. Ex. cellHeight = 100 + textview height. //100 is height which not contain textview height.

3) After calculating height, replace it in above method

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
            return CGSizeMake(50, dynamicheight); //(width,hight)
    }

Loading...

(Visited 2 times, 1 visits today)