【发布时间】:2019-10-24 08:28:38
【问题描述】:
我正在尝试在 SwiftUI 中重新创建使用 UIKit 构建的 UI,但遇到了一些小问题。
我想在这里更改List 的颜色,但似乎没有任何属性可以按我的预期工作。示例代码如下:
struct ListView: View {
@EnvironmentObject var listData: ListData
var body: some View {
NavigationView {
List(listData.items) { item in
ListItemCell(item: item)
}
.content.background(Color.yellow) // not sure what content is defined as here
.background(Image("paper-3")) // this is the entire screen
}
}
}
struct ListItemCell: View {
let item: ListItem
var body: some View {
NavigationButton(destination: Text(item.name)) {
Text("\(item.name) ........................................................................................................................................................................................................")
.background(Color.red) // not the area I'm looking for
}.background(Color.blue) // also not the area I'm looking for
}
}
【问题讨论】:
-
在另一个答案的帮助下,我能够以不同的方式为列表中的每个元素着色,就像在你的屏幕截图中一样。 stackoverflow.com/a/69514684/9439097