【问题标题】:Navigation bar is white, while isTranslucent = false [duplicate]导航栏是白色的,而 isTranslucent = false [重复]
【发布时间】:2017-09-13 22:04:08
【问题描述】:

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

 override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationBar.backgroundColor = UIColor.blue
    self.navigationBar.isTranslucent = false
}

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

以防万一我的导航控制器被覆盖

override var preferredStatusBarStyle: UIStatusBarStyle{ return .lightContent }

并在 AppDelegate 中设置 tint color

UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

评论 tintColor 对我也没有帮助。

【问题讨论】:

    标签: ios objective-c swift uinavigationcontroller


    【解决方案1】:

    你需要设置 barTint 颜色而不是 tintColor

    self.navigationBar.barTintColor = UIColor.blue
    

    【讨论】:

      【解决方案2】:

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

      self.navigationBar.translucent = false
      self.navigationBar.barTintColor = UIColor.blue
      

      【讨论】:

      • Omg... 数小时以来一直在尝试解决此问题.. 一直在使用 backgroundColor。谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多