<分区>
我使用 UICollectionView 并设置水平滚动。现在在这个 ImageView 中,除了单元格间距外,所有工作都很完美。在 collectionView 中,我为单元格 0(零)设置了最小间距。但 Spaces 仍然存在。
我的输出是这样的:
但我需要这种类型的输出:
还有一件事是我引用了很多答案,但仍然不知道该怎么做。我使用 Xcode 7.0,所以我需要 swift 2.0 的解决方案,如果可能的话,还要求在 swift 3.0 中给出答案。
<分区>
我使用 UICollectionView 并设置水平滚动。现在在这个 ImageView 中,除了单元格间距外,所有工作都很完美。在 collectionView 中,我为单元格 0(零)设置了最小间距。但 Spaces 仍然存在。
我的输出是这样的:
但我需要这种类型的输出:
还有一件事是我引用了很多答案,但仍然不知道该怎么做。我使用 Xcode 7.0,所以我需要 swift 2.0 的解决方案,如果可能的话,还要求在 swift 3.0 中给出答案。
最佳答案
不要忘记设置 collectionview flowlayout 委托(delegate):
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: collectionViewTable.bounds.size.width/2 - 20, height: 160)
}
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
insetForSectionAt section: Int) -> UIEdgeInsets
{
return UIEdgeInsetsMake( 5, 14, 5, 14)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 20;
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 20;
}
关于ios - UICollection 水平滚动,因此减少单元格项目之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45386611/