UITabBarItem's appearance

时间:2023-12-28 20:49:50

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

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

UITabBarItem's appearance

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

@implementation TTTabBarController

+(void)initialize{

//normal状态的文字属性
NSMutableDictionary *attrDic = [[NSMutableDictionary alloc]init];
[attrDic setValue:[UIColor grayColor] forKey:NSForegroundColorAttributeName];
[attrDic setValue:[UIFont systemFontOfSize:] forKey:NSFontAttributeName];

//select状态的文字属性
NSMutableDictionary *selectedAttrDic = [[NSMutableDictionary alloc]init];
[selectedAttrDic setValue:[UIColor darkGrayColor] forKey:NSForegroundColorAttributeName];
[selectedAttrDic setValue:[UIFont systemFontOfSize:] forKey:NSFontAttributeName];

//项目中所有tabBarItem都将是这种文字状态
UITabBarItem *item = [UITabBarItem appearance];
[item setTitleTextAttributes:attrDic forState:UIControlStateNormal];//normal状态
[item setTitleTextAttributes:selectedAttrDic forState:UIControlStateSelected];//select状态
}

效果如下:

UITabBarItem's appearance