我想要将视图1的导航标题的 colored颜色 更改为绿色,而不更改视图2的导航标题的 colored颜色 .我看了看this question,实现了完全改变 colored颜色 ,但这并不完全是我需要的.在SwiftUI中,有没有一种方法可以只更改特定视图的NavigationTitle的 colored颜色 ,而不是更改整个NavigationView的 colored颜色 ?
以下是我的代码:
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")
}
}
任何帮助我们都很感激,非常感谢!