【问题标题】:Easy UICollectionView Custom LayoutEasy UICollectionView 自定义布局
【发布时间】:2016-07-10 10:12:33
【问题描述】:

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

我找到了 Ray Wenderlich (https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterest) 的教程,它的功能或多或少是一样的,但对我来说太复杂了,所以我无法根据自己的需要进行调整。

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

【问题讨论】:

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

标签: swift uicollectionview uicollectionviewcell uicollectionviewlayout


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2012-10-11
    • 2015-07-07
    • 1970-01-01
    相关资源
    最近更新 更多