gpt4 book ai didi

ios - 像 Android GridLayout 中的单元格周围的边距

转载 作者:行者123 更新时间:2023-11-28 20:52:59 24 4
gpt4 key购买 nike

在 Android 中很容易创建具有下边距的网格列表:

enter image description here

我找到了这个适用于 iOS 的解决方案,但它不会在单元格和父 View 之间添加边距,只会在单元格之间添加边距

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

enter image description here

我该如何解决?

附言我不想硬编码任何东西,所以它应该适用于所有 iPhone/iPad 设备

最佳答案

let itemSpacing: CGFloat = 3
let itemsInOneLine: CGFloat = 2
let flow = UICollectionView().collectionViewLayout as! UICollectionViewFlowLayout
flow.sectionInset = UIEdgeInsets(top: itemSpacing, left: itemSpacing, bottom: itemSpacing, right: itemSpacing)
flow.minimumInteritemSpacing = itemSpacing
flow.minimumLineSpacing = itemSpacing
let cellWidth = (UIScreen.main.bounds.width - (itemSpacing * 2) - ((itemsInOneLine - 1) * itemSpacing)) / itemsInOneLine
flow.itemSize = CGSize(width: cellWidth, height: cellWidth)

关于ios - 像 Android GridLayout 中的单元格周围的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55659342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com