【问题标题】: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] 更改大标题栏。

    【讨论】:

      猜你喜欢
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 2017-09-11
      • 2012-04-25
      • 2014-08-04
      • 2020-01-19
      • 1970-01-01
      相关资源
      最近更新 更多