我已经以某种方式设置了我的收藏视图,我的第一张图片是完整尺寸的,右边是屏幕尺寸的一半,使用以下代码
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.row == 0 {
return CGSize(width: self.collectionView.frame.width, height: ( self.collectionView.frame.height / 2 ))
}
let width = self.collectionView.frame.width / 3 - 1
return CGSize(width: width, height: width)
}
它运作正常。但是当集合视图只有2个项目时,第二个项目位于中间而不是左侧。
如何解决这个问题?