0

I would like to make UICollectionView as the following image.

enter image description here However, I got the following.

enter image description here I am using UICollectionView flow layout. I used the following code to defined each cell size.

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

I expected the cell 2 will be aligned well to cell 1. However, it flowed to the next column. How can I make the layout as the first image?

Thanks.

user890207
  • 509
  • 1
  • 6
  • 14

1 Answers1

0

You can find good layouts. for example https://github.com/bryceredd/RFQuiltLayout

Yusuf terzi
  • 186
  • 7
  • I have read the source code. It seems this is too much than I need. I read this tutorial: http://skeuo.com/uicollectionview-custom-layout-tutorial, and read apple's document, https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CreatingCustomLayouts/CreatingCustomLayouts.html. Finally I wrote my custom collection view layout, now it works. Thanks! – user890207 Oct 23 '14 at 06:54