这是我更改应用标签栏和导航栏颜色的代码:
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];
答案 0 :(得分:2)
从“blue.jpeg”中查找RGB并将其设置为浅色...
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;
答案 1 :(得分:0)
从更多挖掘中,我了解到将tintColor属性设置为由图像制作的颜色被视为“黑客”。仅支持RGB颜色,并且期望该颜色适用于此属性。所以你有它。由于NDA我无法提供更多细节,但一旦iOS 6公开,我将尝试更新。