更改 tabbar 字體顏色有兩種方法:
第一種:
[tabbarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:selectColor} forState:UIControlStateSelected];
此方法在 iOS 13 會有 bug,當我們 push 到下一頁再次返回時 tabbar 字體顏色設置會失效。
第二種:
self.tabBar.tintColor = selectColor;
此方法在 iOS 13 可以使用,不會出現問題。
ps:
ios 13中使用富文本設置tabbar默認顏色異常
[obj.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont customWithName:@"PingFangSC-Regular" size:10],NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
[obj.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont customWithName:@"PingFangSC-Regular" size:10],NSForegroundColorAttributeName:[UIColor colorWithHex:@"#2C68FF"]} forState:UIControlStateSelected];
修改:
if (@available(iOS 10.0, *)) {
self.tabBar.unselectedItemTintColor = [UIColor blackColor];
self.tabBar.tintColor = [UIColor colorWithHex:@"#2C68FF"];
} else {
// Fallback on earlier versions
}
