如何更改导航栏&返回按钮颜色 iOS 15 [英] How to change navigation bar & back button colour iOS 15

查看:57
本文介绍了如何更改导航栏&返回按钮颜色 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆