码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-06-21 22:30:14      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:const   改变   details   let   source   dict   null   toc   star   

一、如果只是设置选中状态的字体颜色,使用 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的字体颜色

标签:const   改变   details   let   source   dict   null   toc   star   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!