1

UITabBarController的默认颜色为黑色,而UINavigationController的默认颜色为蓝色。我需要将此颜色更改为其他颜色。我怎样才能做到这一点编程?以编程方式更改标签栏和导航栏的颜色

我想我找到了如何更改导航栏的颜色,但我不明白的代码 [navBorder setBackgroundColor:[UIColor colorWithWhite:200.0f/255.f alpha:0.8f]];

我不明白是什么colorWithWhite呢?

无论如何,我如何为UITabBarController添加颜色?

回答

4

要更改iOS 5中的颜色,请设置UITabBarController的tabBartintColor。下面是我做的一个例子:(您可以下载该项目,并尝试一下自己)

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/ch19p533tabBarController/p464p475tabBarController/AppDelegate.m

colorWithWhite:alpha:是用于设置灰色,可能与透明度的快捷方式。

+0

你是对的。 +1给你。 – 2011-12-25 18:15:13

+0

是的,@MichaelDautermann,观察iOS 5中出现的一些真正的花哨和奇怪的界面。你可以为任何*颜色着色! – matt 2011-12-25 18:35:46

3

要改变的UITabBar颜色编程,你可以使用tintcolor属性下面的代码行会帮助你

self.navigationController.navigationBar.tintColor= [UIColor redColor]; 

变化的TabBar颜色

tabBar.tintColor = [UIColor greenColor]; 
+0

+1很好的解决方案.. :) – DShah 2012-01-16 16:51:47

1

有一个在iOS版的外观代理5

UIAppearance.h class 

@Protocol UIAppearance <NSObject> 
+(id) appearance ; 
+(id) appearanceWhenContainedIn:(Class <UIAppearanceContainer> containerClass,..) 
... 

@end 

#define UI_APPEARANCE_SELECTOR 

这将有助于您可以根据需要更改控件的外观... 您还可以观看WWDC 2011会话视频的“自定义UIKit控件的外观”以获取更多信息。

例如: -

[[UINavigationBar appeareance] setBackGroundImage:[UIImage imageNamed:@"navBackground"] forBarMetrics:UIBarMetricsDefault]; 

它改变导航栏图像在应用种源文件夹中navBackground图像,并设置导航栏度量为默认。

[[UIButton ButtonWhenContainedIn:[CustomViewController Class],[UINavigationController Class],nil] setTitleColor:[UIColor redColor] forControlState:UIControlStateNormal]; 

当包含在此层次结构中时,它会将按钮的标题颜色设置为红色。