0

I have used a List of NavigationLink to generate my sidebar but when running as a Mac Catalyst app all selections use the system accent color as their background. This is fine but where the colour is dark I want the text to invert to white like it does in most Mac apps.

Can anyone help? Here's my code:

 List {
            
            ForEach(topics, id: \.self) { topic in
                
                NavigationLink(
                    destination: DetailView(selectedDate: self.titles[topic])
                ) {
                    HStack {
                        Image(topic)
                            Text(self.titles[topic]!)
                }
                 
                }
            
            }
           
            
    }

Btw topic is an array of strings which are the keys for the dictionary titles. Thanks in advance.

Sidebar

sketchyTech
  • 5,746
  • 1
  • 33
  • 56

1 Answers1

0

Have you tried using the new Label(_:) element, instead of a custom HStack with image + text? Swift "2" now has Label which when coupled with the SidebarListStyle should do what you want to. Text goes to highlighted color when selected. Since you're using custom images, I'm not sure what happens there, but give it a try.

Instead of:

HStack {
  Image(...)
  Text(...)
}

Just use:

Label("Formalism", image: "formalism.png")
Procrastin8
  • 4,193
  • 12
  • 25
  • Thanks for the reply I haven't installed the Beta yet, I will download and try this. – sketchyTech Aug 12 '20 at 14:21
  • I've now downloaded the Xcode 12.0 Beta 4 but I don't have Big Sur installed, so I can't test this yet, because `Label` requires a higher level of Mac Catalyst (14.0). Thanks again for your answer, I will return to this question once I have upgraded and if it solves the problem I will mark this as the solution.. – sketchyTech Aug 13 '20 at 12:50