iOS 15 导航栏适配问题

问题一: NavigationBar背景颜色失效,背景色默认透明,滑动时显示

// 在AppDelegate 全局设置导航栏
if #available(iOS 15.0, *) {
     let navAppear = UINavigationBarAppearance()
     //使用默认背景和阴影值配置条形外观对象
     navAppear.configureWithOpaqueBackground()
     //导航条背景色
     navAppear.backgroundColor = UIColor.white
     //这儿可以设置shadowColor透明或设置shadowImage为透明图片去掉导航栏的黑线
     navAppear.shadowColor = UIColor.clear
     navAppear.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white,NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 17)]
     // 不使用毛玻璃效果
     appearance.backgroundEffect = nil; 
     UINavigationBar.appearance().scrollEdgeAppearance = navAppear
     UINavigationBar.appearance().standardAppearance = navAppear
 }

问题二: 在特定控制器中设置导航栏透明不成功

// 首先我们要先设置导航栏背景图片为透明色
self.navigationController?.navigationBar.setBackgroundImage(UIImage.imageWith(color: .clear), for: UIBarMetrics.default)//设置导航栏背景图,此处用颜色替代
// 其次再适配 iOS15 
if #available(iOS 15.0, *) {
     let navAppear = UINavigationBarAppearance()
     //使用默认背景和阴影值配置条形外观对象
     navAppear.configureWithOpaqueBackground()
     //导航条背景色
     navAppear.backgroundColor = UIColor.clear
     //这儿可以设置shadowColor透明或设置shadowImage为透明图片去掉导航栏的黑线
     navAppear.shadowColor = UIColor.clear
     navAppear.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white,NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 17)]
     // 不使用毛玻璃效果
     appearance.backgroundEffect = nil; 
     // 切记此时需要设置当前控制器的 navigationController
     self.navigationController?.navigationBar.scrollEdgeAppearance = navAppear
     self.navigationController?.navigationBar.standardAppearance = navAppear
 }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容