标签:
系统默认是 蓝色。但是当 tabbarItem的 选中图标改成了 灰色后,我们也希望把 文字改成 灰色。这个时候就用到了“
setTitleTextAttributes” 方法。
可以在 “ UITabBarItem ” 类的父类 “ UIBarItem ” 类中找到下面这个方法:
/* You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.
*/
- (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
这个方法是用来改变 文字的颜色。 可以在 “NSAttributedString.h” 类中找到 Keys.
// 默认 NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12]; attrs[NSForegroundColorAttributeName] = [UIColor grayColor]; [essenceVC.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateNormal]; // 选中 NSMutableDictionary *attrSelected = [NSMutableDictionary dictionary]; attrSelected[NSFontAttributeName] = [UIFont systemFontOfSize:12]; attrSelected[NSForegroundColorAttributeName] = [UIColor darkGrayColor]; [essenceVC.tabBarItem setTitleTextAttributes:attrSelected forState:UIControlStateNormal];
标签:
原文地址:http://www.cnblogs.com/iOS363536404/p/5590546.html