我試圖將 SwiftUI 串列和 NavigationLink 與自定義字體/顏色/視圖一起使用 沒有任何效果我嘗試設定 .foregroundColor 并使用其他自定義視圖,但我無法更改文本的顏色,我只想要黑色文本顏色沒什么特別的
struct SettingsView: View {
var body: some View {
List{
Section(header: Text("North America")){
NavigationLink(destination: CASettingsView() ) {
SettingItemView(value: "USA")
}.foregroundColor(.red)
NavigationLink(
destination: Text("Destination"),
label: {
Text("Click Here!")
.foregroundColor(.black)
}
)
}
}
.listStyle(.plain)
}
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
CASettingsView()
}
}

uj5u.com熱心網友回復:
就我而言,它有效。
NavigationLink(destination: Empty()) {
Button("Smth", action: {})
}.foregroundColor(.black)
你只需要使用foregroundColortoNavigationLink而不是Text()
uj5u.com熱心網友回復:
您的 NavigationLinks 是灰色的,因為它們沒有嵌入到 NavigationView 中。將整個串列包裝在 NavigationView { }
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/349199.html
