I want to change to color of the navigationTitle of View1 to green, without changing the color of the navigationTitle of View2. I looked at this question and achieved to change the color at all, but this is not quite what I need. Is there a way in SwiftUI to change only the color of the navigationTitle for a specific view and not the whole NavigationView?
Here is my code:
struct View1: View {
// copied from the question I mentioned above
init() {
let navbarAppearance = UINavigationBarAppearance()
navbarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.green]
navbarAppearance.titleTextAttributes = [.foregroundColor: UIColor.green]
navbarAppearance.configureWithTransparentBackground()
UINavigationBar.appearance().standardAppearance = navbarAppearance
UINavigationBar.appearance().compactAppearance = navbarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navbarAppearance
}
var body: some View {
NavigationView{
NavigationLink(
destination: View2())
{
Text("go to view 2")
}
.navigationTitle("View1")
}
}
}
struct View2: View {
var body: some View {
Text("view2")
.navigationTitle("View2")
}
}
Any help is appreciated, thanks a lot!