状态栏和导航栏的颜色不同,但实际上它们应该是相同的

时间:2018-03-19 15:31:54

标签: ios swift statusbar navigationbar

我有这个扩展,允许我有一些UIView属性(例如backgroundColor):

extension UIApplication {
    var statusBarView: UIView? {
        return value(forKey: "statusBar") as? UIView
    }
}

然后我在应用程序(didFinishLaunchingWithOptions :)中编写此代码

UIApplication.shared.statusBarView?.backgroundColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)
UINavigationBar.appearance().barTintColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)

正如你所看到的颜色是相同的,但结果很奇怪,因为事实上它们是不同的:

enter image description here

看到两种绿色的区别? 为什么会出现这种差异?

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试设置以下值:

UINavigationBar.appearance().shadowImage = UIImage()

如果这没有帮助,请尝试使用以下命令(我在我的应用程序中使用它们将所有内容设置为白色背景):

UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().isTranslucent = false
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
UITabBar.appearance().backgroundColor = UIColor.white
相关问题