swift - 如何实现这种之字形 Collection View 布局?

标签 swift user-interface layout collectionview

下面是我希望单元格的样子,Here's how I want the cells to look like

我在做 indexPath.row % 3 == 0 但不幸的是这不起作用。

最佳答案

和collection view的布局无关,是你想怎么显示cell。

我建议在 collectionView(_:willDisplay:forItemAt:) 中执行此逻辑如下:

假设您的 View Controller 符合 UICollectionViewDelegate:

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    cell.backgroundColor = [.purple, .white, .white, .purple][indexPath.item % 4]
}

感谢@vacawama用于优雅编辑([.purple, .white, .white, .purple][indexPath.item % 4])。

关于swift - 如何实现这种之字形 Collection View 布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49807016/

相关文章:

swift - 无法使用 MLDataTable 访问 .csv 数据

iOS:包裹在导航 Controller 中时将数据传递给模态 VC

ios - UIActionsheet 不显示运行 iOS7 的 iPad 上的所有按钮

python-3.x - Tkinter 列表框 "update"或 "refresh"

Android 使用布局作为模板创建多个布局实例

android - 添加对文本的对角线删除线

ios - 在 AWS 上设置解析服务器时出错

python - 交互式数据可视化 - Python

java - 如何从普通的 java 类调用 javafx

android - 以编程方式用按钮填充屏幕