为所有 UINavigationBars 设置颜色

Set color for all UINavigationBars

我有一个包含多个 UINavigationController 的应用程序。现在我想将它们的背景颜色设置为相同的颜色。我在AppDelegate的application方法中写了这个:

UINavigationBar.appearance().backgroundColor = UIColor.darkGray

UITabBars 的相同语句有效:

UITabBar.appearance().barTintColor = UIColor.darkGray

我的错误是什么?

感谢您的帮助!

必须是UINavigationBar.appearance().barTintColor = UIColor.darkGray