如何从 AppDelegate 更改 UINavigationBar 背景颜色 [英] How to change UINavigationBar background color from the AppDelegate

查看:34
本文介绍了如何从 AppDelegate 更改 UINavigationBar 背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过执行

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nabbar"] forBarMetrics:UIBarMetricsDefault];

而且我知道如何在每个 Views 中将条形设置为不同的颜色......现在我想将背景颜色 不使用图像更改为来自 app delegate 的纯色.我不想每次都从每个视图中设置它,也不想编写 CGRect.

and I know how to set the bar to different colors within each Views..... Now I want to change the background color without using an image to a solid color from the app delegate. I do not want to set it each time from each view and I do not want to write a CGRect.

我试过 [[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:33/255.0 green:34/255.0 blue:36/255.0 alpha:1.0]]; 但我不工作,我无法在应用程序委托中的任何地方找到代码.

I tried [[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:33/255.0 green:34/255.0 blue:36/255.0 alpha:1.0]]; but I doesn't work and I cant find a code anywhere that works in the app delegate.

有人能指出我正确的方向吗?

Could anyone please point me in the right direction?

推荐答案

您可以使用 [[UINavigationBar appearance] setTintColor:myColor];

从 iOS 7 开始,您需要设置 [[UINavigationBar appearance] setBarTintColor:myColor];[[UINavigationBar appearance] setTranslucent:NO].

Since iOS 7 you need to set [[UINavigationBar appearance] setBarTintColor:myColor]; and also [[UINavigationBar appearance] setTranslucent:NO].

[[UINavigationBar appearance] setBarTintColor:myColor];
[[UINavigationBar appearance] setTranslucent:NO];

这篇关于如何从 AppDelegate 更改 UINavigationBar 背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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