与 pushview 控制器保持相同的导航栏颜色

keep same nav bar color with pushview controller

我有一个带有连接到 UIViewcontrollerA 的导航控制器的应用程序。在 UIViewcontrollerA 内部,我有一个表视图,当用户单击一个单元格时,他们将被带到 UIViewcontrollerB。 UIViewcontrollerB 与故事板中的 UIViewcontrollerA 或任何导航控制器没有任何连接。我遇到的问题是单击转到 UIViewcontrollerB 时,导航栏会失去其颜色值。有没有一种方法可以将 UIViewcontrollerA 的值传递给 UIViewcontrollerB,而不必在 UIViewcontrollerB 中手动设置它? 感谢您的帮助!

代码:

if let vc: UIViewcontrollerB = stbrd.instantiateViewController(withIdentifier: UIViewcontrollerB.UIViewcontrollerBIdentifier) as? UIViewcontrollerB {
  self.navigationController?.pushViewController(vc, animated: true)

}

确保在 UIViewControllerB 的身份检查器中您没有禁用导航栏。我之前遇到过这个问题,我不得不将顶部栏设置为 'Inferred'。希望这有帮助。

要更新所有视图控制器上的导航栏外观,请在 appDelegate 的 didFinishLaunchingWithOptions 方法中编写以下代码行:

   UINavigationBar.appearance().barTintColor = .black
    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    UINavigationBar.appearance().isTranslucent = false