Posts

Post not yet marked as solved
3 Replies
4.9k Views
I have an app with a regular NavigationView. The root content is a List in grouped style with a button on the trailing edge of the navigation bar; this is colored blue with the default accent color. The detail views for each item in the list make use of a user-supplied color (part of the model) to provide a header view of sorts, and this looks really nice using .edgesIgnoringSafeArea(.top), extending this nice vibrant color to the top of the display.I'm using a gradient to darken the color towards the bottom enough that I can use a white primary color for text/icons, but for the life of me I can't determine how to change the accent color of the navigation bar, which now has a clear background. On the root view, where the navigation view is defined, I can use .accentColor(.white) or similar to make the back button appear in white, but that effectively makes the navigation bar contents on the root view invisible there. If I skip that, then the back button in the detail view is either all-but invisible (over a blue header background) or rather displeasing (over a red or green background, for example).Ideally there would be a method like .navigationBarAccentColor(_ color: Color?) on View, but that's not there. I wonder if there's a way to use the Preference subsystem to have the accent color read dynamically from a custom PreferenceKey whose value I can replace from subviews—can anyone point me in the right direction here?
Posted
by Jim Dovey.
Last updated
.