首页 > 其他 > 详细

UITabBar 设置选中、未选中状态下title的字体颜色

时间:2018-06-21 21:44:08      阅读:307      评论:0      收藏:0      [点我收藏+]

一、如果只是设置选中状态的字体颜色,使用 tintColor  就可以达到效果

  1. self.tabBar.tintColor = [UIColor redColor];  


二、但如果要将未选中状态和选中状态下的颜色都改变,可以使用 setTitleTextAttributes:<#(nullable NSDictionary<NSString *,id> *)#> forState:<#(UIControlState)#> 达到效果

  1. [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];  
  2. [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]} forState:UIControlStateSelected];  


       或者

    1. [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];  
    2. [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]} forState:UIControlStateSelected]; 

UITabBar 设置选中、未选中状态下title的字体颜色

原文:https://www.cnblogs.com/Free-Thinker/p/9210865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!