【问题标题】:SwiftUI change navigationBarTitle color with button [duplicate]SwiftUI使用按钮更改navigationBarTitle颜色[重复]
【发布时间】:2020-04-16 09:27:13
【问题描述】:
我可以在触摸按钮时更改 navigationBarTitle 颜色吗?
NavigationView {
ZStack {
Color(ThemeManager.shared().generalBackgroundColor)
.edgesIgnoringSafeArea(.all)
} .navigationBarTitle("Change theme sample").foregroundColor(.blue)
}
【问题讨论】:
标签:
swiftui
navigationbar
【解决方案1】:
您目前无法在 SwiftUI 中原生更改导航栏属性,因此您的 .foregroundColor(.blue) 只会更改该屏幕上的所有前景色。
您可以使用this answer 之类的东西来访问UINavigationController,然后用navigationController.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue] 更改大标题栏。