更改背景颜色状态栏iOS

Ari*_*ang 4 uistatusbar swift

所以,我正在努力做到这一点:

在此输入图像描述

我尝试在状态栏后面使用UIView并将颜色设置为橙色,但在运行时,UIView显示在状态栏的正下方,所以它仍然是白色

我在互联网上尝试了很多解决方案,但没有一个能够正常工作.是的它有效但当我移动到其他视图控制器并再次返回时,颜色消失了.我该怎么办?我正在使用swift

小智 20

UIApplication.shared.statusBarStyle = .lightContent

UINavigationBar.appearance().clipsToBounds = true

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView

statusBar.backgroundColor = UIColor.orange
Run Code Online (Sandbox Code Playgroud)

尝试在appDelegate的方法应用程序didFinishLaunchingWithOptions中使用此代码

  • 此解决方案存在一个问题,当您双击主页按钮时,此状态栏颜色将消失。像问题(/sf/ask/3307534681/) (2认同)