2

这是我更改应用程序标签栏和导航栏颜色的代码:

UIColor* color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue.jpeg"]];

//set colors
[[UINavigationBar appearance] setTintColor:color];
[[UITabBar appearance] setTintColor:color];

然而只有标签栏的颜色会改变;导航栏保持黑色。为什么setTintColor:适用于标签栏而不适用于导航栏?

编辑:有趣的是,在真实设备(运行 iOS 5.0.1 的 iPhone 4)上进行测试时,标签栏导航栏的颜色都没有改变;两者都保持黑色。在模拟器上,至少标签栏发生了变化……对此行为有什么解释吗?谢谢!

编辑2:这是我的代码的一部分applicationDidFinishLaunching:

UIColor* color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue.jpeg"]];

//create navigation controllers
firstNavigationController = [[UINavigationController alloc] 
    initWithRootViewController:viewController1];
[[firstNavigationController navigationBar] setTintColor:color];
//[[firstNavigationController navigationBar] setBarStyle:UIBarStyleBlack];

secondNavigationController = [[UINavigationController alloc] 
    initWithRootViewController:viewController2];
[[secondNavigationController navigationBar] setTintColor:color];
//[[secondNavigationController navigationBar] setBarStyle:UIBarStyleBlack];

thirdNavigationController = [[UINavigationController alloc] 
    initWithRootViewController:viewController3];
[[thirdNavigationController navigationBar] setTintColor:color];
//[[thirdNavigationController navigationBar] setBarStyle:UIBarStyleBlack];

fourthNavigationController = [[UINavigationController alloc] 
    initWithRootViewController:viewController4];
[[fourthNavigationController navigationBar] setTintColor:color];
//[[fourthNavigationController navigationBar] setBarStyle:UIBarStyleBlack];

//create tab bar controller
self.tabBarController = [[UITabBarController new] autorelease];
self.tabBarController.delegate = self;

//set controllers
self.tabBarController.viewControllers = [NSArray 
    arrayWithObjects:firstNavigationController, secondNavigationController, 
    thirdNavigationController, fourthNavigationController, nil];
4

2 回答 2

2

从“blue.jpeg”中找到 RGB 并将它们设置为 tint color ...

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:213.0/255.0 green:166.0/255.0 blue:39.0/255.0 alpha:1];

或者当您将图像设置为背景颜色时,您可以使用以下代码...

self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"blue.jpeg"].CGImage;
于 2012-01-25T04:44:24.997 回答
0

从更多的挖掘中,我了解到将 tintColor 属性设置为由图像制成的颜色被认为是“hack”。仅支持 RGB 颜色,并且预计该属性可以正常工作。所以你有它。由于保密协议,我无法提供更多细节,但一旦 iOS 6 公开,我会尝试更新它。

于 2012-06-28T03:36:07.117 回答