Swift 设置单个UICollectionView单元格的大小

Swift 设置单个UICollectionView单元格的大小,swift,uicollectionview,Swift,Uicollectionview,是否有办法仅在UICollectionView中更改第一个单元格的大小,并为其他单元格指定不同的大小 我尝试过这样做,但不起作用: func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { if (indexPa

是否有办法仅在
UICollectionView
中更改第一个单元格的大小,并为其他单元格指定不同的大小

我尝试过这样做,但不起作用:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
    if (indexPath == 0){
        return CGSize(200, height: 200)
    } else {
        return CGSize(300, height: 300)
    }
}

indepath
在集合视图中由两个属性组成,
item
section

无法检查
indepath==0
,因为
0
不是索引路径

if
语句替换为以下内容:

if indexPath == IndexPath(item: 0, section: 0) {

这将为您提供集合视图第一部分中的第一项。

如何显示“它不工作”清单?或者您可以这样做:
如果indexath.section==0&&indexPath.item==0{