使用statusbarmanager

问题描述 投票:0回答:1

this问题旋转:在ios13+上设置状态栏颜色(使用statusbarmanager)在如何将状态栏文本颜色设置为深色或uiviewController的dark或Light。

但没有关于如何动态更改状态栏外观的答案。

这仍然对我有用,但是自iOS 13:

以来,它已经被贬低了。

// inside a function of the viewController //set the status bar background overrideUserInterfaceStyle = darkMode ? .dark : .light // on older iOS, this is not sufficient (tested and failed on ios 15) setNeedsStatusBarAppearanceUpdate() // statusBarStyle is deprecated on iOS 13+ UIApplication.shared.statusBarStyle = nightMode ? .lightContent : .darkMode

这对我不起作用(加载视图时设置了状态栏样式,但以后不更新):

override var preferredStatusBarStyle: UIStatusBarStyle { return darkMode ? .lightContent : .darkContent }

	
swift statusbar darkmode uistatusbar
1个回答
0
投票
info.plist

以下在控制器中给出的实施代码
Appearance

我在

class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) setNeedsStatusBarAppearanceUpdate() } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ override var preferredStatusBarStyle: UIStatusBarStyle { return UIScreen.main.traitCollection.userInterfaceStyle == .dark ? .lightContent : .darkContent } }
中尝试了

检查一下,让我知道您是否有任何问题:)

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.