1

In the app, the user can change the accent color based on a specific set of options. The accent color gets set in this way, however, there is an AccentColor asset that is set as well. I've tried removing this but it didn't resolve the issue.

var body: some Scene {
    WindowGroup {
        ContentView(user: $data.user, saveAction: data.save)
            .onAppear(perform: data.load)
            .tint(data.user.accentColor == nil ? Color("AccentColor") : data.user.accentColor!.getColor())
    }
}

accentColor is stored as a string, and the getColor() function takes the string and returns a Color() for it.

I also have some views that change color based on what the user selects as the accent color. With the current code, it works for everything except for the Back buttons in the navigation bar. Also does the same for the check marks in a Picker. How can I get those to match the color the user selects?

enter image description here

You can see that the accent color is set to orange. And below you can see that the back button is still blue.

enter image description here

If you'd like to test it out. You can setup a content view like what you see below. Leave the AccentColor asset empty, or you can set it to a random color. You'll see that the back button won't change color with what's in tint(). NavigationLinkView is just a view with nothing in it but a List that has a navigation title.

struct ContentView: View {
var body: some View {
    NavigationView {
        List {
            NavigationLink("Test Link", destination: {
                NavigationLinkView()
            })
            
            Button("Fake Button") {
                
            }
        }
        .navigationTitle("Test")
    }
    .tint(.yellow)
}
}

EDIT: After further testing it seems that accentColor() does work, however, Xcode says that'll be deprecated soon and to use tint(). Seems like its an issue with tint().

Joseph Kessler
  • 93
  • 2
  • 11
  • Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and see: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Yrb Nov 12 '21 at 16:39
  • Does this answer your question https://stackoverflow.com/a/60665620/12299030? – Asperi Nov 12 '21 at 16:44
  • 1
    @Asperi Yea I've tried putting that there, as well as tint(), but it still stays pink. – Joseph Kessler Nov 12 '21 at 21:18

0 Answers0