我有UIkit
项目,我想更改导航栏颜色和后退按钮颜色。它在以前的版本上运行良好。但不是在 iOS 15 中。我将以下代码放在AppDelegate
,它是更改标题颜色而不是后退按钮项目颜色。如何修复它?
if #available(iOS 15.0, *) {
let appearance = UINavigationBarAppearance()
let navigationBar = UINavigationBar()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
appearance.backgroundColor = .red
navigationBar.tintColor = .white
navigationBar.standardAppearance = appearance;
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}else{
let navBarAppearnce = UINavigationBar.appearance()
navBarAppearnce.tintColor = .white
navBarAppearnce.barTintColor = .red
navBarAppearnce.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
}
这些行完全没有意义:
let navigationBar = UINavigationBar()
navigationBar.tintColor = .white
navigationBar.standardAppearance = appearance
您正在创建导航栏,对其进行配置,然后将其丢弃。这对您的应用程序没有任何作用。有意义地重写:
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.backgroundColor = .red
let proxy = UINavigationBar.appearance()
proxy.tintColor = .white
proxy.standardAppearance = appearance
proxy.scrollEdgeAppearance = appearance
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句