我正在用代码创建一个TabBar:
self = [super init];
self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController.delegate = self;
self.tabBarController.navigationController.delegate = self;
//Build Model
NSArray *topLevelControllers = [self buildTopLevelControllers];
[self.tabBarController setViewControllers:topLevelControllers animated:NO];
//Inbox will be lead navigation
self.tabBarController.selectedIndex = kSelectedIndex;
[self.view addSubview:self.tabBarController.view];
self.tabBarController.customizableViewControllers = @[];
return self;
}在App中,我有Tint的以下代码:
[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];问题:当应用程序启动时,Tab栏中的所有图标都带有全局颜色。当我选择一个,然后取消选择它,他们回到灰色(图像默认颜色)。
想要的结果:当应用程序启动时,所有的按钮都是灰色的(灰色是PNG中的图像颜色)。当我点击选项卡栏图标时,颜色会改变为全局色调。
尝试了:在应用程序委托中,我添加了以下代码,但它不起作用:
TabBarVC *tabBarVC = [[TabBarVC alloc]init];
tabBarVC.tabBarController.tabBar.tintColor = [UIColor greyColor];
tabBarVC.tabBarController.tabBar.selectedImageTintColor = [STColorUtils globalTintColor];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [ColorUtils globalTintColor]}];
[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];
[self.window setRootViewController:tabBarVC];然而,如果我评论一下:
//[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];图标显示为灰色,但全局色调颜色为iOS7默认值:蓝色。
发布于 2014-03-26 14:58:35
selectedImageTintColor在iOS 7中有一个已知的问题。最后我检查了一下,这个问题还没有解决。所以把-
tabBarVC.tabBarController.tabBar.selectedImageTintColor = [STColorUtils globalTintColor];另外,您还想使用UITabBar的外观,所以请替换
[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];使用
[[UITabBar appearance] setTintColor:[ColorUtils globalTintColor]];发布于 2015-01-18 14:51:42
这是迄今为止我找到的最好的解决方案:
[UIView appearance].tintColor = [UIColor redColor];
// the selected image and text will still use UIView.tintColor.
// this is to tint the unselected images until they are tapped
// [UIColor grayColor] does not exactly match the default color, but it's subtle
[UIView appearanceWhenContainedIn:[UITabBar class], nil].tintColor = [UIColor grayColor];当使用UIView时,我需要创建一个目标-c文件,其中包含一个+(viewAppearanceWhenContainedInTabBar *)viewAppearanceWhenContainedInTabBar()方法,以便使用UIView appearanceWhenContainedIn:方法,因为它不适用于UIView :(
发布于 2014-03-26 14:53:31
更改UIWindow的tintColor属性。它应用于添加到此窗口的每个UIView。
https://stackoverflow.com/questions/22664246
复制相似问题