如何在导航栏中删除此类颜色?

时间:2018-02-14 20:59:38

标签: ios swift uinavigationcontroller

我正在尝试创建自定义导航栏。但是当我给导航栏上的颜色比其他灰色颜色来的时候我遇到了问题。在这里我尝试

let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 15, width: self.view.frame.size.width,height: 50))

        navigationBar.backgroundColor = UIColor.red
        navigationBar.isTranslucent = true
        self.view.addSubview(navigationBar)

enter image description here

1 个答案:

答案 0 :(得分:2)

使用barTintColor代替backgroundColor

let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 15, width: self.view.frame.size.width,height: 50))
navigationBar.barTintColor = .red
navigationBar.isTranslucent = true
self.view.addSubview(navigationBar)