【发布时间】:2017-02-15 14:55:26
【问题描述】:
我想将状态栏颜色设置为与导航栏相同的颜色。当我尝试将导航栏和状态栏设置为相同颜色时,导航栏总是以比状态栏更浅的颜色显示。
这就是我想要的:
我的结果:
AppDelegate 中的代码:
状态栏:
UIApplication.sharedApplication().statusBarStyle = .Default
let statusBar: UIView = UIApplication.sharedApplication().valueForKey("statusBar") as! UIView
if statusBar.respondsToSelector(Selector("setBackgroundColor:"))
{
statusBar.backgroundColor = UIColor(red: 43/255.0, green: 79/255.0, blue: 133/255.0, alpha: 1.0)
statusBar.tintColor = UIColor(red: 43/255.0, green: 79/255.0, blue: 133/255.0, alpha: 1.0)
}
导航栏:
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UINavigationBar.appearance().backgroundColor = UIColor(red: 43/255.0, green: 79/255.0, blue: 133/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UIApplication.sharedApplication().statusBarHidden = false
UIApplication.sharedApplication().statusBarStyle = .Default
谁能给我任何关于如何解决这个问题的建议。
提前致谢!
【问题讨论】:
-
用相同的导航颜色设置视图的颜色,这会做你想要的
-
这不是你使用
whiteColor作为状态栏上UINavigationBar和UIColor(red: 43/255.0, green: 79/255.0, blue: 133/255.0, alpha: 1.0)的颜色那么简单 -
请更新到 Swift 3。
-
是的,这是下一步,当前版本是 Swift 2.3。升级到 Swift 3.0 后,某些功能不再起作用,这就是我将其留在 Swift 2.3 中的原因。但我们已经忙于解决问题。由于我们需要尽快将其交出,因此这是将其留在 Swift 2.3 中的唯一解决方案。
标签: swift uinavigationbar uistatusbar