SwiftUI - 如何更改嵌套在表单中的选择器的复选标记颜色
SwiftUI - How to change the checkmark color of a Picker which is nested in a Form
我正在尝试更改 SwiftUI 中复选标记的颜色,它在嵌套在表单内的选择器中使用。我试过:
UINavigationBar.appearance().tintColor = .black
但这只是改变了“<返回”的颜色。
struct ContentView: View {
@State private var selectedMode = 0
private var modes = ["#1", "#2"]
var body: some View {
NavigationView {
Form {
Section(header:Text("").font(.title)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
){
Picker(selection: $selectedMode, label: Text("Modes")) {
ForEach(0 ..< modes.count, id: \.self) {
Text(self.modes[[=10=]])
.foregroundColor(Color.red)
}
}
}
}
}
}
}
在这里(用Xcode 11.4测试)
var body: some View {
NavigationView {
Form {
Section(header:Text("").font(.title)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
){
Picker(selection: $selectedMode, label: Text("Modes")) {
ForEach(0 ..< modes.count, id: \.self) {
Text(self.modes[[=10=]])
.foregroundColor(Color.red)
}
}
}
}
}.accentColor(Color.black) // << fix !!
}
注意: .accentColor
应用于所有 NavigationView
控件,因此不需要 UINavigationBar.appearance().tintColor = .black
。
我正在尝试更改 SwiftUI 中复选标记的颜色,它在嵌套在表单内的选择器中使用。我试过:
UINavigationBar.appearance().tintColor = .black
但这只是改变了“<返回”的颜色。
struct ContentView: View {
@State private var selectedMode = 0
private var modes = ["#1", "#2"]
var body: some View {
NavigationView {
Form {
Section(header:Text("").font(.title)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
){
Picker(selection: $selectedMode, label: Text("Modes")) {
ForEach(0 ..< modes.count, id: \.self) {
Text(self.modes[[=10=]])
.foregroundColor(Color.red)
}
}
}
}
}
}
}
在这里(用Xcode 11.4测试)
var body: some View {
NavigationView {
Form {
Section(header:Text("").font(.title)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
){
Picker(selection: $selectedMode, label: Text("Modes")) {
ForEach(0 ..< modes.count, id: \.self) {
Text(self.modes[[=10=]])
.foregroundColor(Color.red)
}
}
}
}
}.accentColor(Color.black) // << fix !!
}
注意: .accentColor
应用于所有 NavigationView
控件,因此不需要 UINavigationBar.appearance().tintColor = .black
。