簡體   English   中英

SwiftUI - 如何更改嵌套在表單中的選取器的復選標記顏色

[英]SwiftUI - How to change the checkmark color of a Picker which is nested in a Form

我正在嘗試更改 SwiftUI 中復選標記的顏色,該復選標記用於嵌套在表單中的選取器中。 我試過了:

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 !!
}

注意: .accentColor適用於所有NavigationView控件,因此不需要UINavigationBar.appearance().tintColor =.black

備份

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM