iOS13 导航栏大标题未覆盖状态栏 [英] iOS13 Navigation bar large titles not covering status bar
问题描述
在 ios13 上,使用 iphone x,大标题导航不会覆盖状态栏,但是当滚动和过渡到传统导航栏时,它可以完美运行.这不会影响没有缺口的设备.
On ios13, with iphone x, the large title navigation does not cover the status bar however when scrolling and transitioning into the traditional nav bar, it works perfectly. This doesn't affect devices without the notch.
大标题
传统导航栏
这一切都嵌入在导航控制器中,所以我不知道为什么会发生这种情况.干杯
It's all embedded within a navigation controller so i'm lost as to why this is happening. Cheers
推荐答案
自定义 UINavigationBar 的官方方法,在 iOS 13 之前,是这样的:
The official way to customize the UINavigationBar, pre iOS 13, is this:
// text/button color
UINavigationBar.appearance().tintColor = .white
// background color
UINavigationBar.appearance().barTintColor = .purple
// required to disable blur effect & allow barTintColor to work
UINavigationBar.appearance().isTranslucent = false
iOS 13 改变了导航栏的工作方式,所以你需要做一些稍微不同的事情来支持旧版和新:
iOS 13 has changed how navigation bars work, so you'll need to do things slightly differently to support both old & new:
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .purple
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().barTintColor = .purple
UINavigationBar.appearance().isTranslucent = false
}
这篇关于iOS13 导航栏大标题未覆盖状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!