如何更改状态栏样式-iOS 12 [英] How to change status bar style - 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屋!