相关疑难解决方法(0)

如何更改导航栏和后退按钮颜色 iOS 15

我有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]
}
Run Code Online (Sandbox Code Playgroud)

输出

uinavigationbar uikit swift uinavigationbarappearance ios15

10
推荐指数
1
解决办法
1万
查看次数