【发布时间】:2018-08-28 05:39:42
【问题描述】:
我有这个扩展,它允许我拥有一些 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)
你可以看到颜色是一样的,但是结果很奇怪,因为实际上它们是不同的:
看到两种绿色之间的区别了吗? 为什么会出现这种差异?
谢谢!
【问题讨论】:
-
谢谢@SandeepBhandari,但这是嵌入在 UINavigationController 中的。
-
该扩展程序中的代码很脆弱,可能会在未来的某些 iOS 更新中崩溃。
-
@rmaddy 是的,我也这么认为,但我怎样才能改进它并用字符串删除 kvo?
-
我从来不需要编写任何代码来更改状态栏的颜色,并且我的应用程序正确地为导航栏和状态栏显示相同的颜色。它只是发生在你身上。
-
我需要它在向上滑动时隐藏导航栏
标签: ios swift statusbar navigationbar