2017-08-07 82 views
-2

有没有办法来改变第一小区的大小仅在UICollectionView并指定其他细胞不同的大小?个人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) 
    } 
} 
+0

“不起作用”如何显示? –

回答

0

IndexPath由两个属性,itemsection的,集合视图中。

你不能检查,如果indexPath == 0因为0不是索引路径。

用以下替换您if声明:

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

这将使你在集合视图的第一部分中的第一项。

+1

或者你可以这样做:'if indexPath.section == 0 && indexPath.item == 0 {'' – rmaddy