【发布时间】:2021-03-19 02:54:03
【问题描述】:
我想要实现的是具有不同背景颜色的表单。但我希望里面的项目始终使用浅色模式变体(深色文本颜色)。但不是完整的视图。我已经搜索过,但找不到任何解决方案。
我尝试listRowBackground 更改有效项目的背景,preferredColorScheme 使用灯光模式,但这将使完整视图处于灯光模式:
...
Form {
DatePicker(selection: $date, displayedComponents: .date) { ... }
.listRowBackground(Color.yellow)
TextField("Name", text: $name)
.listRowBackground(Color.yellow)
Picker("amount", selection: $amount) {
ForEach(amounts, id: \.self) {
Text($0)
}
}
.listRowBackground(Color.yellow)
Button(action: { ... }) {
Label("More", systemImage: "chevron.up")
}
.listRowBackground(Color.yellow)
}
.preferredColorScheme(.light)
...
【问题讨论】: