【发布时间】:2020-03-18 16:04:12
【问题描述】:
我的 collectionview 图像未调整大小。我在包含集合视图的视图控制器中使用以下内容,并且当单元格为空时它的大小正确;但是,如果里面有一个 imageview,它的行为就不正常了。
谢谢!
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let noOfCellsInRow = 2
let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
let totalSpace = flowLayout.sectionInset.left
+ flowLayout.sectionInset.right
+ (flowLayout.minimumInteritemSpacing * CGFloat(noOfCellsInRow - 1))
let size = Int((collectionView.bounds.width - totalSpace) / CGFloat(noOfCellsInRow))
return CGSize(width: size, height: size)
}
【问题讨论】:
标签: swift uicollectionview autolayout