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)


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

你可能感兴趣的:(UITabbar修改字体颜色)