这是我更改应用程序标签栏和导航栏颜色的代码:
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];