gpt4 book ai didi

swift - 如何在 SwiftUI 中修改列表的背景颜色?

转载 作者:搜寻专家 更新时间:2023-10-30 21:52:25 27 4
gpt4 key购买 nike

我正在尝试在 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
}
}

I want to change the WHITE area

最佳答案

好的,我找到了为列表行着色的解决方案:

struct TestRow: View {

var body: some View {
Text("This is a row!")
.listRowBackground(Color.green)
}
}

然后在正文中:

List {
TestRow()
TestRow()
TestRow()
}

这如我所料,但我还没有找到如何删除行之间的分隔线...

关于swift - 如何在 SwiftUI 中修改列表的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56517904/

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