gpt4 book ai didi

ios - 带有备用背景颜色的 SwiftUI 列表

转载 作者:行者123 更新时间:2023-12-01 15:41:25 25 4
gpt4 key购买 nike

在 SwiftUI 中,TableView 被替换为 List。

有没有办法改变列表单元格/行的背景颜色?

我想实现这样的东西,

if (indexPath.row % 2 == 0) { 
aCell.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 1.0)
}

见文章 https://medium.com/@ronm333/improving-the-appearance-of-ios-tableviews-9effb7184efb一个很好的例子。

最佳答案

我使用这些方法在我的 SwiftUI 列表中交替列表背景颜色

List {
ForEach(items.indices) { index in
Text(items[index])
.listRowBackground((index % 2 == 0) ? Color(.systemBlue) : Color(.white))
}
}

关于ios - 带有备用背景颜色的 SwiftUI 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57919062/

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