如何更改状态栏样式-iOS 12 [英] How to change status bar style - iOS 12

查看:181
本文介绍了如何更改状态栏样式-iOS 12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据背景颜色(UINavigationController自动执行的操作)在每个视图控制器上更新状态栏样式.

I need to update status bar style on every view controller based on the background color (what UINavigationController is doing automatically).

已经尝试了关于stackoverflow的所有选项(info.plist中的View controller-based status bar appearance设置为 YES ),但是没有一个对我有用.

Have tried all the options described on stackoverflow (View controller-based status bar appearance in info.plist set to YES), but none worked for me.

我正在使用针对iOS 12的Xcode 10 beta 6和Swift 4.2.

I am using Xcode 10 beta 6 and Swift 4.2, targeting iOS 12.

推荐答案

info.plist中将View controller-based status bar appearance设置为NO,并在每个视图控制器中覆盖preferredStatusBarStyle,如下所示:

Set View controller-based status bar appearance to NO in the info.plist and override preferredStatusBarStyle in each view controller like so:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

然后在视图控制器中调用setNeedsStatusBarAppearanceUpdate()(例如,在viewDidLoad()中).

And call setNeedsStatusBarAppearanceUpdate() in your view controller (in viewDidLoad() for example).

这篇关于如何更改状态栏样式-iOS 12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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