【问题标题】:How to set spacing between collectionview cells in Swift 3?如何在 Swift 3 中设置集合视图单元格之间的间距?
【发布时间】:2017-11-14 05:14:46
【问题描述】:

目前我正在使用 swift 3 和故事板,谷歌搜索所有内容并查看了所有 stackoverflow 类似问题,到目前为止一无所获。

在我的示例项目中,

我的收藏视图如下所示 Simulator Screenshot

这不是我想要的,我想要一个完全没有间距的网格布局,我编辑了情节提要的值,在那里没有任何东西,所以我使用了这个代码

  let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
let width = UIScreen.main.bounds.width
layout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
layout.itemSize = CGSize(width: width / 2, height: width / 2)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
collectionView!.collectionViewLayout = layout

也没有用:(

【问题讨论】:

标签: swift layout uicollectionview


【解决方案1】:
'if let layout = self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout{
            let width = UIScreen.main.bounds.width
            layout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
            layout.itemSize = CGSize(width: width / 2, height: width / 2)
            layout.minimumInteritemSpacing = 0
            layout.minimumLineSpacing = 0
        }'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多