苹果iOS13在外观上做了很多改变,导航栏就是其中之一。
什么改变了?
- 在iOS13中,大标题风格导航栏的默认外观已经从半透明变成透明。
- 在普通样式的表视图中没有什么变化,导航栏将显示表视图的颜色,在本例中是白色。对于分组样式,也有一些抵消性的更改。
- 这些变化并不大,但如果你的设计依赖于这个彩色条,你可能需要调整你的设计或添加一些代码回到旧的外观风格。
如何回到老样子?
如果你想要半透明的风格放回应用程序以下代码(_:didFinishLaunchingWithOptions:)。
let appearance = UINavigationBarAppearance()
appearance.configureWithDefaultBackground()
UINavigationBar.appearance().scrollEdgeAppearance = appearance
如果你有彩色导航栏,你必须为scrollEdgeAppearance和standardAppearance设置外观。
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithOpaqueBackground()
coloredAppearance.backgroundColor = .systemPink
coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
什么是标准/紧凑/滚动边缘外观? (standard/compact/scroll edge appearance)
- 标准外观表示常规高度的导航栏,没有大标题。此外观将用于形成默认设置
- 紧凑外观表示高度紧凑的导航栏
- 最后一个是滚动条外观,基于WWDC会话,更新了iOS 13的用户界面,这个将用于与滚动视图关联的导航,但在我的测试中,这个将用于大标题导航栏,即使它没有滚动视图