我想将View1的导航标题颜色更改为绿色,而不更改View2的导航标题颜色。 我查看了此问题,并成功更改了所有颜色,但这不符合我的需求。 在SwiftUI中,是否有一种方法仅更改特定视图的导航标题颜色而不更改整个NavigationView的颜色?
以下是我的代码:
以下是我的代码:
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")
}
}
非常感谢您提供的任何帮助!