首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS: Tabbar Tint颜色

iOS: Tabbar Tint颜色
EN

Stack Overflow用户
提问于 2014-03-26 14:34:34
回答 3查看 2.6K关注 0票数 1

我正在用代码创建一个TabBar:

代码语言:javascript
复制
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的以下代码:

代码语言:javascript
复制
[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];

问题:当应用程序启动时,Tab栏中的所有图标都带有全局颜色。当我选择一个,然后取消选择它,他们回到灰色(图像默认颜色)。

想要的结果:当应用程序启动时,所有的按钮都是灰色的(灰色是PNG中的图像颜色)。当我点击选项卡栏图标时,颜色会改变为全局色调。

尝试了:在应用程序委托中,我添加了以下代码,但它不起作用:

代码语言:javascript
复制
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];

然而,如果我评论一下:

代码语言:javascript
复制
//[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];

图标显示为灰色,但全局色调颜色为iOS7默认值:蓝色。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-03-26 14:58:35

selectedImageTintColor在iOS 7中有一个已知的问题。最后我检查了一下,这个问题还没有解决。所以把-

代码语言:javascript
复制
tabBarVC.tabBarController.tabBar.selectedImageTintColor = [STColorUtils globalTintColor];

另外,您还想使用UITabBar的外观,所以请替换

代码语言:javascript
复制
[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];

使用

代码语言:javascript
复制
[[UITabBar appearance] setTintColor:[ColorUtils globalTintColor]];
票数 3
EN

Stack Overflow用户

发布于 2015-01-18 14:51:42

这是迄今为止我找到的最好的解决方案:

代码语言:javascript
复制
[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 :(

票数 2
EN

Stack Overflow用户

发布于 2014-03-26 14:53:31

更改UIWindow的tintColor属性。它应用于添加到此窗口的每个UIView。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22664246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档