Hi
I reviewed this post: How to change navigation title color in swiftUI
This seems to work fine if the intention is to apply the title color across an application. I would like to apply a different text title color selectively depending on the View being shown. And in some instances revert back to the color depending on the light and dark themes.
Same result occurs using a viewmodifier or simply using onAppear
and onDisappear
with the title color is applied to all views. And if you do modify it in onDisappear
, when you navigate back to another view which changes the color onAppear
it has the same color as the previous view.
The only way I've found this to work is using UIViewControllerRepresentable
and handling the viewWillAppear
and viewWillDisappear
something like this:
NavigationBarView(
viewWillAppear: { nav in
nav.navigationBar.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
},
viewWillDisappear: { nav in
nav.navigationBar.largeTitleTextAttributes = nil
}
)
Has anyone been successful in getting a different title text color to apply to different views using a modifier or onAppear
and onDisappear
?
Appreciate any guidance.