UICollectionViewFlowLayout minimumInteritemSpacing不起作用 [英] UICollectionViewFlowLayout minimumInteritemSpacing doesn't work
问题描述
我的UICollectionView有两个问题:
I've got two problems with my UICollectionView:
-
minimumInteritemSpacing
不起作用 - 它在iOS 6上水平溢出
minimumInteritemSpacing
doesn't work- it overflows horizontally on iOS 6
我这样设置布局:
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(70.0f, 70.0f);
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.minimumLineSpacing = 0.0f;
layout.minimumInteritemSpacing = 0.0f;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
// I set the size of _collectionView in layoutSubviews:
// _collectionView.frame = self.bounds;
_collectionView.contentInset = UIEdgeInsetsMake(8.0f, 8.0f, 8.0f, 8.0f);
该图显示了在iOS 6上的结果(在iOS 7上没有溢出,但是列之间的间距仍然不为零)
The image shows the result on iOS 6 (on iOS 7 there is no overflow, but the spacing between columns is still not zero)
我尝试了此解决方案 https://gist.github.com/OliverLetterer/5583087 ,但这并不能解决我的情况.
I tried this solution https://gist.github.com/OliverLetterer/5583087, but it doesn't fix anything in my case.
推荐答案
来自minimumInterItemSpacing
属性的文档:
对于水平滚动网格,此值表示同一列中项目之间的最小间距.该间距用于计算一行中可以容纳多少个物品,但是确定了物品数量后,实际间距可能会向上调整.
流布局将在整个宽度上均匀分布单元格,其间距不小于,小于您设置的最小值.如果您不希望有间距,则需要实现自己的布局.
The flow layout will evenly space cells across its width, with a spacing of no smaller than the minimum you set. If you don't want the spacing, you'll need to implement your own layout.
我不确定iOS 6溢出问题.尝试放弃对iOS 6的支持;)
The iOS 6 overflow issue I'm not sure about. Try dropping support for iOS 6 ;)
这篇关于UICollectionViewFlowLayout minimumInteritemSpacing不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!