ios - 如何更改状态栏的背景颜色?
问题描述
我不想在我的应用程序中使用半透明的导航栏。所以,我添加了这段代码来改变它。它有效,但有一个小问题。如果我使用 largeTitle 导航,状态栏颜色看起来是灰色的。我该如何处理?提前致谢。
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = UIColor.white
UINavigationBar.appearance().backgroundColor = UIColor.white
解决方案
您可以通过使用在状态栏顶部添加子视图来修复它UIStatusBarManager
。
if #available(iOS 13, *) {
let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.map({$0 as? UIWindowScene})
.compactMap({$0})
.first?.windows
.filter({$0.isKeyWindow}).first
let statusBar = UIView(frame: (keyWindow?.windowScene?.statusBarManager?.statusBarFrame)!)
statusBar.backgroundColor = .white
keyWindow?.addSubview(statusBar)
}
推荐阅读
- recursion - 查找具有 n 个元素的集合的 k 个元素子集的递归方法
- java - 不同颜色的安卓圆形背景
- multithreading - 当线程驻留在两个不同的 CPU 中时,它们可以共享数据吗?
- sql - SQL Server 使用正则表达式从字符串中提取整数
- arrays - 使用 ReactJS (typeScript) 匹配类型 .Net Core
- python - Python - 嵌套列表中二进制搜索算法的时间复杂度
- r - R:生存分析广义伽玛参数拟合置信区间计算
- r - Meta分析流程图
- c++ - C++14和C++17的默认构造函数调用区别
- functional-programming - 在 RXJS 中执行“有条件的压缩”更简单/更惯用的方法?