目前我正在使用swift 3和storyboard,谷歌搜索所有内容并查看所有stackoverflow类似问题,到目前为止一无所获。
在我的示例Porject上,
我的Collection视图看起来像这样 Simulator Screenshot
这不是我想要的,我想要一个没有间距的网格布局,我编辑了故事板值ddin't there there there,所以为此我使用了这段代码
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
也不起作用:(
答案 0 :(得分:2)
'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
}'