【问题标题】:iOS 16 status bar height is getting wrong on iPhone 14 seriesiOS 16 状态栏高度在 iPhone 14 系列上出现错误
【发布时间】:2022-10-07 22:02:28
【问题描述】:

我已经尝试过这个solution 来获取带有 iOS 16 的 iPhone 14 系列的状态栏高度,但尺寸错误。不使用应用场景委托。

【问题讨论】:

    标签: ios swift storyboard ios16


    【解决方案1】:

    请尝试以下适用于 iPhone 14 Pro 和 iPhone 14 max Pro 的解决方案

    if #available(iOS 13.0, *) {
                let window = UIApplication.shared.windows.first
                let topPadding = window?.safeAreaInsets.top
                let statusBar = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: topPadding ?? 0.0))
                statusBar.backgroundColor = UIColor(named: "AppPrimaryColor")
                UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.addSubview(statusBar)
        }
    

    希望这能解决您的问题。继续编码:)

    【讨论】:

      猜你喜欢
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2022-08-16
      相关资源
      最近更新 更多