How to adjust height of UICollectionView to be the height of the content size of the UICollectionView?

后端 未结 14 1155
死守一世寂寞
死守一世寂寞 2020-11-28 03:51

I would like the UICollectionView (The red one) to shrink to the height of the content size in this case UICollectionViewCells(the yellow ones) because there is a lot of emp

14条回答
  •  没有蜡笔的小新
    2020-11-28 04:29

    first of all calculate number of cells than multiply it with height of cell and then return height in this method

        collectionView.frame = CGRectMake (x,y,w,collectionView.collectionViewLayout.collectionViewContentSize.height); //objective c
        //[collectionView reloadData];
       collectionView.frame = CGRect(x: 0, y: 0, width: width, height: collectionView.collectionViewLayout.collectionViewContentSize.height) // swift
    

提交回复
热议问题