简体   繁体   English

SwiftUI NavigationLink Item foregroundColor 不起作用

[英]SwiftUI NavigationLink Item foregroundColor not working

Im trying to use SwiftUI List & NavigationLink with custom font/colors/view Nothing is working I tried setting the .foregroundColor and using other View customized yet i cant change the color of the text, i only want to have a black text color nothing fancy我试图将 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()
    }
}

在此处输入图片说明

In my case it works.就我而言,它有效。

NavigationLink(destination: Empty()) {
    Button("Smth", action: {})
}.foregroundColor(.black)

You just need to use foregroundColor to NavigationLink instead of Text()您只需要使用foregroundColorNavigationLink而不是Text()

Your NavigationLinks are greyed out because they aren't embedded in a NavigationView.您的 NavigationLinks 是灰色的,因为它们没有嵌入到 NavigationView 中。 Wrap your whole list in NavigationView { }将整个列表包装在 NavigationView { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM