繁体   English   中英

选择后如何显示不同的标签栏图标颜色

[英]How have different tab bar icon color when selected

我想知道是否有一种方法可以为UITabBarController选择的不同图标提供不同的颜色,我知道:

[[UITabBar appearance] setTintColor:[UIColor whiteColor]];

我可以更改所有图标的选择颜色,但是如何为其他选项卡呢?

一种方法是简单地更改不同视图控制器中标签栏的颜色。

假设您有3个不同的标签: tab1tab2tab3 ,它们都显示不同的viewcontrollers。 现在,假设您要在tab1使用蓝色,但在tab2tab3使用红色。 然后,您可以简单地viewWillAppear:下行添加到不同ViewControllersviewWillAppear:方法。

对于第一个viewController(显示在tab1 ,您将具有:

//In your viewcontroller which is shown in tab1
- (void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   // change tint color to blue
   [self.tabBarController.tabBar setTintColor:[UIColor blueColor]];
}

对于其他两个,您只需放置另一种颜色:

//In your viewcontrollers which are shown in tab2 and tab3
- (void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   // change tint color to red
   [self.tabBarController.tabBar setTintColor:[UIColor redColor]];
}

就这么简单。 当然,还有其他方法可以做到这一点,但是这一方法非常干净直接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM