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

后端 未结 14 1082
死守一世寂寞
死守一世寂寞 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:25

    1) Set Fix Height of your CollectionView.

    2) Create Outlet of this CollectionView Height Constant. Like :

    IBOutlet NSLayoutConstraint *constHeight;

    3) Add below method in your .m file:

    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
    
        CGFloat height = collectionMenu.collectionViewLayout.collectionViewContentSize.height;
        constHeight.constant = height;
    }
    

提交回复
热议问题