列表的SwiftUI系统颜色



我有一个列表,我想突出显示所选的行
这适用于:

struct ContentView: View {
var body: some View {
List {
Line(text: "Line 1")
Line(text: "Line 2")
Line(text: "Line 3",selected: true)
Line(text: "Line 4")
}
}
}
struct Line: View {
var text :String
var selected = false
var body: some View {
Text(text)
.listRowBackground(selected ? Color.blue : Color.white)
.foregroundColor(selected ? Color.white : Color.black)
}
}

然而,当切换到暗模式时,它看起来很难看
当然,我可以检测暗模式并明确设置颜色,但我正在寻找一种方法,将"未选择"行的颜色设置为列表的标准前景色和背景色
如何获得这些"Systemcolors">

访问系统颜色的一种简单方法是使用这样的Color(UIColor(:

var body: some View {
Text(text)
.listRowBackground(Color(.systemBackground))
.foregroundColor(Color(.label))
}

最新更新