简体   繁体   中英

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

    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()

Your NavigationLinks are greyed out because they aren't embedded in a NavigationView. Wrap your whole list in NavigationView { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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