我想指定行数,列数以及集合视图单元格项目之间的间隔,然后我希望单元格的宽度和高度由ios确定。怎么做 ?请检查我的以下代码脚本。当我更改行和列的数量时,有时我看不到单元格之间的间距相等。如何看到始终相等的空间,以及想要的行和列。
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout:
UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
let layout = collectionViewLayout as! UICollectionViewFlowLayout;
layout.minimumInteritemSpacing = 0.6
layout.minimumLineSpacing = 0.6
let remainingInterSpace = collectionView.frame.width - (layout.minimumInteritemSpacing*(numberOfColumns-1))
let remainingLineSpace = collectionView.frame.height - (layout.minimumLineSpacing*(numberOfRows-1))
let width = remainingInterSpace / numberOfColumns
let height = remainingLineSpace / numberOfRows
return CGSize(width: width, height: height)
}