如何使用swift更改一个视图控制器中的状态栏颜色? [英] how to change statusbar color in one view controller using swift?

查看:22
本文介绍了如何使用swift更改一个视图控制器中的状态栏颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)

我使用这个将所有应用程序中的状态栏更改为亮起.但是现在我只需要在一个 View Controller 中将它改回黑色.我该怎么做?

I use this one to change status bar to light in all app. But now I need to change it in just one View Controller back to black. How can I do that?

推荐答案

将 project.plist 中的 View controller-based status bar appearance 设置为 NO

Set View controller-based status bar appearance in your project.plist to NO

使用 viewWillAppearviewWillDisappear 来设置和重置 statusBarStyle,同时保持一个属性和之前的 statusBarStyle 一样

Use viewWillAppear and will viewWillDisappear to set and reset the statusBarStyle, while keeping a property with the previous statusBarStyle like this

let initialStatusBarStyle : UIStatusBarStyle

func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    initialStatusBarStyle = UIApplication.sharedApplication().statusBarStyle
    UIApplication.sharedApplication().setStatusBarStyle(.LightContent, animated: animated)
}

func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    UIApplication.sharedApplication().setStatusBarStyle(initialStatusBarStyle, animated: animated)
}

这篇关于如何使用swift更改一个视图控制器中的状态栏颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆