当它的bg颜色设置为黑色时,UINavigationBar是白色的

时间:2016-08-03 09:50:34

标签: ios swift uinavigationbar

我不明白为什么会这样。这是我的代码:

UINavigationBar.appearance().backgroundColor = UIColor.blackColor()
UINavigationBar.appearance().translucent = false

1 个答案:

答案 0 :(得分:1)

backgroundColor更改为barTintColor

试试这个

UINavigationBar.appearance().barTintColor = UIColor.blackColor()
UINavigationBar.appearance().translucent = false

<强> e.g

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
    UINavigationBar.appearance().barTintColor = UIColor.blackColor()
    UINavigationBar.appearance().translucent = false

    return true
}

或使用

   self.navigationController!.navigationBar.barTintColor = UIColor.blackColor()
    self.navigationController!.navigationBar.translucent = false

<强> e.g

 override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController!.navigationBar.barTintColor = UIColor.blackColor()
    self.navigationController!.navigationBar.translucent = false

      }