UITabBarItem's appearance

1.我们知道,用tabBarController创建出来默认的tabBar似这个样子滴。。。

-----------------我是图片分割线--------------------------------

UITabBarItem's appearance_第1张图片

2.通常通过appearance统一设置,可以一劳永逸,不必在每个控制器设置

@implementation TTTabBarController

+(void)initialize{
    
//normal状态的文字属性 NSMutableDictionary
*attrDic = [[NSMutableDictionary alloc]init]; [attrDic setValue:[UIColor grayColor] forKey:NSForegroundColorAttributeName]; [attrDic setValue:[UIFont systemFontOfSize:10] forKey:NSFontAttributeName];
//select状态的文字属性 NSMutableDictionary
*selectedAttrDic = [[NSMutableDictionary alloc]init]; [selectedAttrDic setValue:[UIColor darkGrayColor] forKey:NSForegroundColorAttributeName]; [selectedAttrDic setValue:[UIFont systemFontOfSize:10] forKey:NSFontAttributeName];
//项目中所有tabBarItem都将是这种文字状态 UITabBarItem
*item = [UITabBarItem appearance]; [item setTitleTextAttributes:attrDic forState:UIControlStateNormal];//normal状态 [item setTitleTextAttributes:selectedAttrDic forState:UIControlStateSelected];//select状态 }

效果如下:

转载于:https://www.cnblogs.com/yintingting/p/4540326.html

你可能感兴趣的:(UITabBarItem's appearance)