2014-10-22 42 views
0

我想使UICollectionView成爲以下圖像。如何使uicollectionview作爲附加圖像

enter image description here 但是,我得到以下。

enter image description here 我正在使用UICollectionView流佈局。我用下面的代碼來定義每個單元格的大小。

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
// return CGSizeMake(kScreenWidth*1.0/2 - 10, kScreenHeight*1.0/3.0 - 10); 
    if (indexPath.row == 0) { 
     return CGSizeMake(kScreenWidth*2.0/3 - 20, kScreenHeight*2.0/3.0 - 10); 
    } else if (indexPath.row == 1 || indexPath.row == 2 || indexPath.row == 3 || indexPath.row == 4 ||indexPath.row == 5) { 
     return CGSizeMake(kScreenWidth*1.0/3 - 30, kScreenHeight*1.0/3.0 - 10); 
    } else { 
     return CGSizeMake(kScreenWidth*1.0/2 - 10, kScreenHeight*1.0/3.0 - 10); 
    } 
} 

我預計單元格2將與單元格1良好對齊。但是,它流到了下一列。我怎樣才能使佈局成爲第一個圖像?

謝謝。

回答

0

你可以找到很好的佈局。例如https://github.com/bryceredd/RFQuiltLayout

+0

我已閱讀源代碼。看起來這比我需要的要多得多。我閱讀本教程:http://skeuo.com/uicollectionview-custom-layout-tutorial,並閱讀蘋果的文檔,https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CreatingCustomLayouts/ CreatingCustomLayouts.html。最後,我寫了我的自定義集合視圖佈局,現在它工作。謝謝! – user890207 2014-10-23 06:54:32