导航栏为白色,而isTranslucent = false

dan*_*nd1 2 objective-c uinavigationcontroller ios swift

我有一个主导航控制器,在其中设置背景颜色

 override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationBar.backgroundColor = UIColor.blue
    self.navigationBar.isTranslucent = false
}
Run Code Online (Sandbox Code Playgroud)

但是,在那种情况下,我的导航栏会变成完全白色。当我将isTranslucent设置为true时,我的导航栏将变为透明,但这实际上不是我所需要的。我只想有蓝色的导航栏。

以防万一在我的导航控制器中

override var preferredStatusBarStyle: UIStatusBarStyle{ return .lightContent }
Run Code Online (Sandbox Code Playgroud)

并在AppDelegate中设置色调颜色

UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
Run Code Online (Sandbox Code Playgroud)

评论tintColor也没有帮助我。

这是我的“蓝色”导航栏

Nis*_*ndi 5

使用下面的代码更改导航栏的颜色。

self.navigationBar.translucent = false
self.navigationBar.barTintColor = UIColor.blue
Run Code Online (Sandbox Code Playgroud)