Kuh*_*ann 4 uinavigationbar swift swiftui
我正在尝试更改 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[$0])
.foregroundColor(Color.red)
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是(用 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 !!
}
Run Code Online (Sandbox Code Playgroud)
注意: .accentColor适用于所有NavigationView控件,因此UINavigationBar.appearance().tintColor = .black不需要。
| 归档时间: |
|
| 查看次数: |
2171 次 |
| 最近记录: |