UITabbar修改字体颜色

在继承 UITabBarController 的子类中加入以下代码

oc:

+ (void)initialize

{

//获取当前这个类下面的所有的tabBarItem

UITabBarItem *item;

if (CurrentDeviceVersion < 9.0) {

item = [UITabBarItem appearanceWhenContainedIn:self, nil];

} else {

item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];

}

NSMutableDictionary *attSelected = [NSMutableDictionary dictionary];

attSelected[NSForegroundColorAttributeName] = [UIColor colorWithR:113 G:179 B:217];

[item setTitleTextAttributes:attSelected forState:UIControlStateSelected];

NSMutableDictionary *attNormal = [NSMutableDictionary dictionary];

attNormal[NSForegroundColorAttributeName] = [UIColor darkGrayColor];

attNormal[NSFontAttributeName] = [UIFont systemFontOfSize:14.0];

[item setTitleTextAttributes:attNormal forState:UIControlStateNormal];

}


swift:

vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)

vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 14)], for: .normal)

(vc为继承自UITabBarController的类的childViewController)


纯属个人笔记,如有错误,欢迎指出。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容