简单的 UICollectionView 自定义布局

Easy UICollectionView Custom Layout

我想创建一个自定义布局,它看起来应该像这里的图片:Custom Layout

我找到了 Ray Wenderlich (https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterest) 的教程,它的功能大致相同,但对我来说太复杂了,所以我无法将其转换为我的需要。

我只需要简单的布局,我也知道我的单元格的大小,我不需要计算它们。 谁能帮帮我。

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

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

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