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

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

问题描述

我知道如何通过执行



更改 UINavigationBar 背景图片> [[UINavigationBar外观] setBackgroundImage:[UIImage imageNamed:@nabbar] forBarMetrics:UIBarMetricsDefault];

我知道如何在每个 / code> .....现在我想从应用程式代表中变更背景颜色而不使用图片为纯色。我不想每次从每个视图设置它,我不想写一个 CGRect



我尝试了 [[UINavigationBar外观] setBackgroundColor:[UIColor colorWithRed:33 / 255.0 green:34 / 255.0 blue:36 / 255.0 alpha:1.0]]; 工作,我无法找到一个代码在任何地方工作在应用程序委派。



任何人都可以指出正确的方向?

解决方案

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



c $ c> [[UINavigationBar appearance] setBarTintColor:myColor]; 以及 [[UINavigationBar appearance] setTranslucent:NO]

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


I know how to change the UINavigationBar background image by doing

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

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.

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?

解决方案

You can use [[UINavigationBar appearance] setTintColor:myColor];

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天全站免登陆