[英]SwiftUI: NavigationBar title displayMode and appearance in iOS 15
In SwiftUI, I set .inline
display mode for navigationBarTitle
.在 SwiftUI 中,我为
navigationBarTitle
设置了.inline
显示模式。
I also use UINavigationBarAppearance
and set background color.我还使用
UINavigationBarAppearance
并设置背景颜色。
But iOS 15 navigationBar
is so weird.但是 iOS 15 的
navigationBar
实在是太奇怪了。
I set UINavigationBarAppearance
config in AppDelegate
.我在
AppDelegate
设置了UINavigationBarAppearance
配置。
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = UIColor.beige
UINavigationBar.appearance().standardAppearance = appearance
iOS 14 is normal iOS 14 正常
iOS 15 navigationBar
background color not change iOS 15
navigationBar
背景颜色未更改
[ [
So I found solution for iOS 15 navigationBar
background color.所以我找到了 iOS 15
navigationBar
背景颜色的解决方案。
Add scrollEdgeAppearance
can solve it.添加
scrollEdgeAppearance
可以解决。
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = UIColor.beige
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
But it will have problem.但是会有问题。
How do I solve the extra area and let it like iOS 14 version?如何解决多余的区域并让它像 iOS 14 版本一样?
I also set standardAppearance
for scrollEdgeAppearance
but it not working.我还设置
standardAppearance
为scrollEdgeAppearance
但它不能正常工作。
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = UIColor.beige
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = UINavigationBar.appearance().standardAppearance
I always achieve this by setting it in the init() of the content view我总是通过在内容视图的 init() 中设置它来实现这一点
init()
{
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.backgroundColor = UIColor(mainColor)
UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().compactAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.