【问题标题】:how to reduce the top space between collectionviewcell and collection view如何减少collectionviewcell和collection view之间的顶部空间
【发布时间】:2018-10-23 20:01:06
【问题描述】:

我在我的项目中使用集合视图。

在集合视图和集合视图单元之间总是有一个点击填充。

我想设置集合视图单元格和它的集合视图容器之间的空间。

我该怎么做?

【问题讨论】:

    标签: ios uicollectionview uicollectionviewcell padding


    【解决方案1】:

    查看 UICollectionViewDelegateFlowLayout :https://developer.apple.com/documentation/uikit/uicollectionviewdelegateflowlayout

    你可以使用这个方法告诉集合视图你想要多少行/列之间的空间:

    func collectionView(_ collectionView: UICollectionView, 
         layout collectionViewLayout: UICollectionViewLayout,  
         minimumLineSpacingForSectionAt section: Int) -> CGFloat {
         return 0
    }
    

    在此处了解该方法:https://developer.apple.com/documentation/uikit/uicollectionviewdelegateflowlayout/1617705-collectionview

    确保您已设置了 collectionView 委托。

    【讨论】: