给tabBar设置图片和字体颜色的几种方法
-
现在很多应用都使用到了tabBar,我们往往在给tabBar设置图片和字体的时候,当选中状态下,往往字体的颜色和图片的颜色不匹配,有时候就显得无从下手,我也常常忘了,所有写这个博客的目的,相当于给自己做个笔记,也希望给有需要的朋友们一点帮助。写了个小demo,来演示这个问题:
-
写了个小demo,来演示这个问题:
-
- (void)viewDidLoad { [super viewDidLoad]; ZYGroupBuyViewController *group = [[ZYGroupBuyViewController alloc]init]; [self createVC:group Title:@"团购" imageName:@"icon_tabbar_homepage"]; ZYVisitTableViewController *visit = [[ZYVisitTableViewController alloc]init]; [self createVC:visit Title:@"上门" imageName:@"icon_tabbar_onsite"]; ZYBusinessViewController *business = [[ZYBusinessViewController alloc]init]; [self createVC:business Title:@"商家" imageName:@"icon_tabbar_merchant"]; ZYProfileViewController *profile = [[ZYProfileViewController alloc]init]; [self createVC:profile Title:@"我的" imageName:@"icon_tabbar_mine"]; ZYMoreViewController *more = [[ZYMoreViewController alloc]init]; [self createVC:more Title:@"更多" imageName:@"icon_tabbar_misc"]; }
- 第一种方法:
-
[vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:159/255.0 alpha:1]} forState:UIControlStateSelected];
- 第二种方法
-
self.tabBar.tintColor = [UIColor colorWithRed:68/255.0 green:173/255.0 blue:159/255.0 alpha:1];
-