首页 > 代码库 > 修改UITabBarItem的字体颜色

修改UITabBarItem的字体颜色

修改UITabBarItem下面字体的颜色,如图:

技术分享

[[UITabBarItemappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];

    [[UITabBarItemappearance] setTitleTextAttributes:   [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],UITextAttributeTextColor,nil]forState:UIControlStateSelected];

这个时候会报警告‘UITextAttributeTextColor‘ is deprecated in iOS 7. The iOS 7 key is ‘NSForegroundColorAttributeName

然后替换一下就可以了,不过NSForegroundColorAttributeName最底支持到ios6.0

[[UITabBarItemappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];

    [[UITabBarItemappearance] setTitleTextAttributes:  [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],NSForegroundColorAttributeName,nil]forState:UIControlStateSelected];


修改UITabBarItem的字体颜色