gpt4 book ai didi

ios - UICollectionView 间距不相等

转载 作者:行者123 更新时间:2023-11-30 12:19:26 26 4
gpt4 key购买 nike

我有一个具有标准宽度和可变高度单元格的垂直UICollectionView。我对间距有疑问。对于单元格的每个高度,单元格后面的间距不同:

UICollectionView 的屏幕截图

最佳答案

UICollectionView 具有 delegate属性(property)。您应该实现 UICollectionViewDelegateFlowLayout在某些类中,例如 View Controller 。

此方法负责间距:

// Space around the section.
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
}

// In case of vertical layout this is a vertical space between horizontal rows inside of each section
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 20
}

// Horizontal space between items in row
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 20
}

关于ios - UICollectionView 间距不相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44978806/

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