修改UITabBarItem的(de)字體顔色
發表時(shí)間:2021-1-10
發布人(rén):融晨科技
浏覽次數:55
修改UITabBarItem下面字體的(de)顔色,如圖:
[img]http://img.blog.csdn.net/20150108133337062
[[UITabBarItemappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
[[UITabBarItemappearance] setTitleTextAttributes: [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],UITextAttributeTextColor,nil]forState:UIControlStateSelected];
這(zhè)個(gè)時(shí)候會報警告'UITextAttributeTextColor' is deprecated in iOS 7. The iOS 7 key is 'NSForegroundColorAttributeName
然後替換一下就(jiù)可以(yǐ)了(le/liǎo),不(bù)過NSForegroundColorAttributeName最底支持到(dào)ios6.0
[[UITabBarItemappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
[[UITabBarItemappearance] setTitleTextAttributes: [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],NSForegroundColorAttributeName,nil]forState:UIControlStateSelected];
以(yǐ)上(shàng)是(shì)改變字體顔色的(de),圖片顔色無法改變,
[[UITabBar appearance]setTintColor:[UIColor redColor]];
但是(shì)上(shàng)面這(zhè)一句就(jiù)可以(yǐ)改變并設置點擊後的(de)圖片和(hé / huò)文字顔色了(le/liǎo)。