gpt4 book ai didi

ios - 如何使用 2 个或更多自定义单元格创建自定义 UICollectionView?

转载 作者:技术小花猫 更新时间:2023-10-29 10:36:33 25 4
gpt4 key购买 nike

在我的项目中,我想将 UICollectionView 与自定义单元格一起使用,我创建了带有自定义单元格的 Collection View ,但我想在我的项目中使用不同大小的自定义单元格我遵循了一些教程,但我不喜欢`没有正确理解,下面我附上了我真正在寻找 Collection View 的示例屏幕截图。
Example image enter image description here

最佳答案

创建它的一种可能方法是使用 sizeForItemAtIndexPath,然后返回您的 Cell 的大小。以下是 Github 上一些有用的链接,它们正是您想要的:

  1. RF Quilt Layout
  2. Mosaic Layout

如第一张图片所示,一些单元格有按钮,而另一些则没有。为此,您必须创建自定义单元格,即一个带有按钮的自定义单元格和一个不带按钮的自定义单元格。在您的 cellForItemAtIndexPath 函数中,您可以使用一些 if-else 条件来定义它们。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(firstCellConditionMet)
{
CustomCell1 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellIdentifier" forIndexPath:indexPath];

//Your code

return cell;
}
else{
CustomCell2 *cell2 = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellIdentifier2" forIndexPath:indexPath];

//Your Code

return cell2;
}
}
}

关于ios - 如何使用 2 个或更多自定义单元格创建自定义 UICollectionView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31731675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com