ios UICollectionView - setting auto height

2019-05-23 11:15发布

I'm using UICollection view to create 3x4 matrix of buttons. Its good looking in iPhone4 with has small height. Also collection view is not scrolling, as it shows 3x4 matrix buttons in available space.
Now when I run the same app on iPHone5, i see lots of space at the bottom below the matrix of buttons. I would like collection view to increase the vertical spacing between the cells. Can some one guide me please?

1条回答
趁早两清
2楼-- · 2019-05-23 11:46

Make UICollectionViewFlowLayout by math, for example:

CGRect mainRect = [[UIScreen mainScreen] bounds];
CGFloat mainWidth = mainRect.size.width;
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumLineSpacing = mainWidth/10;
flowLayout.itemSize = CGSizeMake(mainWidth/4, mainWidth/4);

Then just assign because UICollectionViewFlowLayout : UICollectionViewLayout

self.collectionView.collectionViewLayout = flowLayout;
查看更多
登录 后发表回答