ios UICollectionView - 设置自动高度 [英] ios UICollectionView - setting auto height

查看:94
本文介绍了ios UICollectionView - 设置自动高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UICollection 视图来创建 3x4 的按钮矩阵.它在iPhone4中很好看,但高度较小.集合视图也不会滚动,因为它在可用空间中显示 3x4 矩阵按钮.
现在,当我在 iPHone5 上运行相同的应用程序时,我看到按钮矩阵下方的底部有很多空间.我希望集合视图增加单元格之间的垂直间距.有人可以指导我吗?

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?

推荐答案

通过数学制作 UICollectionViewFlowLayout,例如:

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);

然后只分配因为 UICollectionViewFlowLayout : UICollectionViewLayout

Then just assign because UICollectionViewFlowLayout : UICollectionViewLayout

self.collectionView.collectionViewLayout = flowLayout;

这篇关于ios UICollectionView - 设置自动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆