ios UICollectionView - setting auto height

谁说胖子不能爱 提交于 2019-12-22 13:53:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!