iOS15下UIKit项目修改导航栏及返回按钮颜色失效如何解决
问题点
- iOS15分支中你给临时创建的
UINavigationBar实例设置tintColor,该配置不会作用到全局导航栏,返回按钮颜色由UINavigationBar.appearance().tintColor控制 - 未配置
UINavigationBarAppearance的返回按钮属性,iOS15后返回按钮样式可通过该配置统一生效
修复代码
if #available(iOS 15.0, *) { let appearance = UINavigationBarAppearance() appearance.configureWithOpaqueBackground() appearance.titleTextAttributes = [.foregroundColor: UIColor.white] appearance.backgroundColor = .red // 配置返回按钮文字颜色 appearance.backButtonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white] // 全局外观配置 let globalNavBarAppearance = UINavigationBar.appearance() globalNavBarAppearance.tintColor = .white globalNavBarAppearance.standardAppearance = appearance globalNavBarAppearance.scrollEdgeAppearance = appearance } else { let navBarAppearance = UINavigationBar.appearance() navBarAppearance.tintColor = .white navBarAppearance.barTintColor = .red navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white] }
最终效果

内容的提问来源于stack exchange,提问作者Dilan
相关产品推荐
相关产品推荐

