2017-08-07 78 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