【发布时间】:2019-04-12 20:59:38
【问题描述】:
在 Android 中,创建带有下边距的网格列表很容易:
我为 iOS 找到了这个解决方案,但它不会在单元格和父视图之间添加边距,仅在单元格之间添加边距
let itemSpacing: CGFloat = 3
let itemsInOneLine: CGFloat = 2
flow.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
let width = UIScreen.main.bounds.size.width - itemSpacing * CGFloat(itemsInOneLine - 1) //collectionView.frame.width is the same as UIScreen.main.bounds.size.width here.
flow.itemSize = CGSize(width: floor(width/itemsInOneLine), height: width/itemsInOneLine)
flow.minimumInteritemSpacing = 3
flow.minimumLineSpacing = 3
我该如何解决?
附:我不想硬编码任何东西,所以它应该适用于所有 iPhone/iPad 设备
【问题讨论】:
-
将 flow.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) 改为 flow.sectionInset = UIEdgeInsets(top: 5, left: 5, bottom: 5,对:5)
-
@RajeshKumarR 什么? i.postimg.cc/ZRSrbPkq/Screenshot-at-Apr-13-19-33-22.png
标签: ios uicollectionview uicollectionviewcell uicollectionviewflowlayout