我试图改变SwiftUI中的复选标记的颜色,这个复选标记是在嵌套在Form中的Picker中使用的。我试着用以下方法来改变它
UINavigationBar.appearance().tintColor = .black
但这只是改变了"< Back "的颜色。
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[$0])
.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[$0])
.foregroundColor(Color.red)
}
}
}
}
}.accentColor(Color.black) // << fix !!
}
请注意,在Xcode 11.4中测试。 .accentColor
适用于所有 NavigationView
控制,所以 UINavigationBar.appearance().tintColor = .black
不需要。