如何在自定义CollectionViewController中设置单元格左对齐

时间:2017-02-23 12:36:14

标签: ios swift swift3

我已经以某种方式设置了我的收藏视图,我的第一张图片是完整尺寸的,右边是屏幕尺寸的一半,使用以下代码

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)
    }

enter image description here

它运作正常。但是当集合视图只有2个项目时,第二个项目位于中间而不是左侧。

如何解决这个问题?

0 个答案:

没有答案