问题
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:
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;
来源:https://stackoverflow.com/questions/15721559/ios-uicollectionview-setting-auto-height