2015-07-10 55 views
0
InViewDidLoad 
    UIApplication.sharedApplication().statusBarStyle = .LightContent 

override func viewWillDisappear(animated: Bool) { 
     super.viewWillDisappear(animated) 

     UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default 

    } 

通过参考我已经实现的上述链接。但状态栏颜色不会改变只有文本在状态栏上正在改变。 Changing the Status Bar Color for specific ViewControllers using Swift in iOS8如何使用swift在特定视图中更改状态栏颜色?

回答

0

如果您的应用程序使用的是导航栏,则状态栏颜色将更改为与导航栏的颜色相匹配。

如果没有导航栏,您可以在状态栏后面放置一个20点高的视图(例如,填充了颜色的某个视图),这就是用户将看到的颜色。

我发现了上述信息in this article

要迅速做到这一点,也许这样做:

// make a view tall enough to fit under the status bar 
var statusBarView: UIView = UIView(frame: CGRectMake(0.0, 0.0, 320.0, 20.0)) 

// give it some color 
statusBarView.backgroundColor = UIColor.redColor() 

// and add it to your view controller's view 
view.addSubview(statusBarView) 
0

有状态栏默认背后没有独立的后台视图。它实际上只是覆盖在主视图的顶部,所以背景采用了这种颜色。

所以,如果你有一个嵌入导航控制器的视图,它将采用导航栏的颜色。如果不是,那么它只会采用主视图的颜色。

您可以创建一个单独的视图,位于状态栏顶部的下方并设置其背景。正如Michael所说,以下代码应该做到这一点,但我已经将宽度更改为设备的宽度,因此它适用于所有情况。

var statusBarView: UIView = UIView(frame: CGRectMake(0.0, 0.0, UIScreen.mainScreen().bounds.width, 20.0)) 
statusBarView.backgroundColor = UIColor.redColor() 
view.addSubview(statusBarView) 
相关问题