状态栏和导航栏的颜色不同,但实际上它们应该是相同的
Different colours for status bar and for navigation bar but actually they should be the same
我有这个扩展,它允许我拥有一些 UIView 属性(例如 backgroundColor):
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
然后我在application(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)
如你所见,颜色相同,但结果很奇怪,因为实际上它们是不同的:
看到两种绿色的区别了吗?
为什么会出现这种差异?
谢谢!
尝试设置以下值:
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
我有这个扩展,它允许我拥有一些 UIView 属性(例如 backgroundColor):
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
然后我在application(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)
如你所见,颜色相同,但结果很奇怪,因为实际上它们是不同的:
看到两种绿色的区别了吗? 为什么会出现这种差异?
谢谢!
尝试设置以下值:
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