How to change navigation bar amp; back button colour iOS 15(如何更改导航栏amp;返回按钮颜色 iOS 15)
问题描述
我有 UIkit
项目,我想更改导航栏颜色和后退按钮颜色.它在以前的版本上运行良好.但不是在 iOS 15 中.我将以下代码放在 AppDelegate
上,它是更改标题颜色而不是后退按钮项目颜色.如何解决?
I have UIkit
project and I want to change navigation bar colour and back button colour.It is working fine on previous versions. but not in iOS 15. I put following code on AppDelegate
,It is change the Title colour but not back button item colour.How to fix it?
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
您正在创建导航栏,对其进行配置,然后将其丢弃.这对您的应用程序没有任何帮助.有意义地重写:
You are creating a navigation bar, configuring it, and throwing it away. That does nothing for your app. Rewrite meaningfully:
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
这篇关于如何更改导航栏&返回按钮颜色 iOS 15的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改导航栏&返回按钮颜色 iOS 15


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01