【发布时间】:2012-01-25 04:28:09
【问题描述】:
这是我更改应用标签栏和导航栏颜色的代码:
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];
【问题讨论】:
-
在这里快速尝试一下。专门引用一个 UINavigationBar 并更改它的 tintColor 属性,而不是去全局实现看看是否可行。
标签: ios uinavigationbar uitabbar uicolor appearance