在 NavigationView 的 SwiftUI 列表中设置雪佛龙的颜色
Set Color of Chevron in a SwiftUI List in a NavigationView
我有一个 NavigationView 列表。
在黑暗模式下,人字形(红色圆圈)几乎看不见。
如何在列表中设置 V 形的颜色。
struct ContentView: View {
var body: some View {
NavigationView{
List {
Line(text: "Line 1")
Line(text: "Line 2")
Line(text: "Line 3",selected: true)
Line(text: "Line 4")
Line(text: "Line 5")
}
}
}
}
struct Line: View {
var text :String
var selected = false
@Environment(\.colorScheme) var colorScheme
var body: some View {
NavigationLink(destination: Text("D")) { Text(text)}
.listRowBackground(selected ? Color.blue : Color(.systemBackground))
.foregroundColor(selected ? Color.white : Color(.label))
.onTapGesture(perform: {print ("tap")
} )
}
}
标准人字形不是光栅图像的符号,这里是
这就是为什么它不会对任何变色修饰剂产生反应。
解决方案,禁用标准人字形并使用自己的自定义(列表的行为相同),如下所示
HStack {
Text(text)
NavigationLink(destination: Text("D")) { EmptyView() } // disabled !
Image(systemName: "chevron.right") // << custom !!
.foregroundColor(Color.red) // any color !!!
}
在我的环境中,默认 V 形显示在自定义 V 形下方。
添加不透明度(0),有效。
NavigationLink(destination: Text("D")) { EmptyView() }
.opacity(0) // Add this
您可以使用 accentColor
属性:
struct ContentView: View {
var body: some View {
NavigationView{
List {
Line(text: "Line 1")
Line(text: "Line 2")
Line(text: "Line 3",selected: true)
Line(text: "Line 4")
Line(text: "Line 5")
}.accentColor(.black)
}
}
}
我有一个 NavigationView 列表。
在黑暗模式下,人字形(红色圆圈)几乎看不见。
struct ContentView: View {
var body: some View {
NavigationView{
List {
Line(text: "Line 1")
Line(text: "Line 2")
Line(text: "Line 3",selected: true)
Line(text: "Line 4")
Line(text: "Line 5")
}
}
}
}
struct Line: View {
var text :String
var selected = false
@Environment(\.colorScheme) var colorScheme
var body: some View {
NavigationLink(destination: Text("D")) { Text(text)}
.listRowBackground(selected ? Color.blue : Color(.systemBackground))
.foregroundColor(selected ? Color.white : Color(.label))
.onTapGesture(perform: {print ("tap")
} )
}
}
标准人字形不是光栅图像的符号,这里是
这就是为什么它不会对任何变色修饰剂产生反应。
解决方案,禁用标准人字形并使用自己的自定义(列表的行为相同),如下所示
HStack {
Text(text)
NavigationLink(destination: Text("D")) { EmptyView() } // disabled !
Image(systemName: "chevron.right") // << custom !!
.foregroundColor(Color.red) // any color !!!
}
在我的环境中,默认 V 形显示在自定义 V 形下方。
添加不透明度(0),有效。
NavigationLink(destination: Text("D")) { EmptyView() }
.opacity(0) // Add this
您可以使用 accentColor
属性:
struct ContentView: View {
var body: some View {
NavigationView{
List {
Line(text: "Line 1")
Line(text: "Line 2")
Line(text: "Line 3",selected: true)
Line(text: "Line 4")
Line(text: "Line 5")
}.accentColor(.black)
}
}
}