-2

我想创建一个自定义布局应该看起来像图片浏览:Custom Layout易UICollectionView自定义布局

我发现了一个教程,通过该做或多或少同样的雷Wenderlich(https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterest),但它是复杂的所以我无法将这转移到我的需要。

我只需要简单的布局,我也知道我的细胞的大小,我不必计算它们。 任何人都可以请帮助我。

+0

这种布局是流布局所以使用委托方法 - (CGSize)的CollectionView: (UICollectionView *)collectionView布局:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {return CGSizeMake(50,50); }并根据indexPath传递大小。 – kaushal

回答

0

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
UICollectionViewDataSource

为变量创建indexPath.row一个switch并设置单元的大小:

cell.frame = CGMake(height: myHeight; width: myWidth)