答案 0 :(得分:0)
所有这些都是流程布局的属性,我们必须在集合视图开始布局单元格之前对其进行设置,这也可以通过编程方式设置
let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
现在您可以使用上方的layout
变量来设置通过属性检查器设置的所有参数
答案 1 :(得分:0)
您应该使用UICollectionViewFlowLayout 使用以下代码作为参考。
let cellSide: CGFloat = yourCustomCellSide
let leftOrRightMargin: CGFloat = yourCustomSideMargin
let sizeRect = UIScreen.main.bounds
let deviceWidth = sizeRect.size.width
let availableWidth = deviceWidth - (cellSide * 4)
let customFlowLayout = UICollectionViewFlowLayout()
customFlowLayout.scrollDirection = .horizontal
customFlowLayout.sectionInset = UIEdgeInsets(top: 10, left: leftOrRightMargin, bottom: 10, right: leftOrRightMargin)
customFlowLayout.minimumInteritemSpacing = 0
customFlowLayout.minimumLineSpacing = availableWidth/4
customFlowLayout.itemSize = CGSize(width: cellSide, height: cellSide)
yourCollectionView.collectionViewLayout = customFlowLayout