// // CustomCollectionViewFlowLayout.swift // wallpaper_project import UIKit class CustomCollectionViewFlowLayout: UICollectionViewFlowLayout { override func prepare() { super.prepare() guard let collectionView = collectionView else { return } // let availableWidth = collectionView.bounds.width - sectionInset.left - sectionInset.right - minimumInteritemSpacing let itemWidth = (collectionView.bounds.width - minimumInteritemSpacing * 3) / 2 itemSize = CGSize(width: itemWidth, height: 300) // 设置每个单元格的大小 minimumLineSpacing = 10 // 设置行间距 minimumInteritemSpacing = 10 // 设置列间距 sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10) } }