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


基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01