swift - 更改背景颜色状态栏 iOS

标签 swift uistatusbar

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

enter image description here

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

我在互联网上尝试了很多解决方案,但没有一个有效。是的,它可以工作,但是当我移动到其他 View Controller 并再次返回时,颜色消失了。我应该怎么办?我正在使用 swift

最佳答案

UIApplication.shared.statusBarStyle = .lightContent

UINavigationBar.appearance().clipsToBounds = true

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

statusBar.backgroundColor = UIColor.orange

尝试在您的 appDelegate 方法 application didFinishLaunchingWithOptions 中使用此代码

关于swift - 更改背景颜色状态栏 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37831114/

相关文章:

swift - 尝试更改 UIStatusBar 色调颜色

iOS 如何从底部滑入 View ,占导航栏+状态栏高度

iphone - 当应用程序转到后台时如何创建 "return to app"状态栏?

swift - 如何处理 Process.run 抛出的异常

swift - 将 Java 三部分 for 循环转换为 Swift

ios - 隐藏 UIStatusBar 后 UIView 未自动调整大小

ios - 无法为 View 设置 iOS 状态栏颜色

swift - 通过共享表从 NSData 共享 PDF

ios - 结构数组不在闭包外更新

ios - 为什么我的 UILabel 对象不会显示在其 super View 中?