UICollectionViewFlowLayout minimumInteritemSpacing 不起作用 [英] UICollectionViewFlowLayout minimumInteritemSpacing doesn't work
问题描述
我的 UICollectionView 有两个问题:
I've got two problems with my UICollectionView:
minimumInteritemSpacing
不起作用- 它在 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
属性的文档:
对于水平滚动的网格,该值表示同一列中项目之间的最小间距.这个间距是用来计算一行可以放多少个item,但是在item个数确定之后,实际间距可能会向上调整.
For a horizontally scrolling grid, this value represents the minimum spacing between items in the same column. This spacing is used to compute how many items can fit in a single line, but after the number of items is determined, the actual spacing may possibly be adjusted upward.
流布局将在其宽度上均匀排列单元格,间距不小于您设置的最小值.如果您不想要间距,则需要实现自己的布局.
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屋!