在使用tabBarViewController的時候盲再,會遇到在tabBar中顯示的圖片和顏色被渲染成為藍(lán)色的問題蛋济。
解決方法如下:
1棍鳖、關(guān)閉圖片的自動渲染
UIImage *selectImg = [UIImage imageNamed:[NSString stringWithFormat:@"icon.png"]];
selectImg = [selectImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
VC.tabBarItem.selectedImage=selectImage;
這種方法可以單獨將圖片設(shè)置成為禁止進(jìn)行自動渲染。
2碗旅、整體設(shè)置圖片的顏色(可分被選擇狀態(tài)和正常狀態(tài))
UITabBarItem *itm=[UITabBarItem appearance];
[itm setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor groupTableViewBackgroundColor]} forState:UIControlStateNormal];
[itm setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
3渡处、將系統(tǒng)渲染的顏色進(jìn)行更改
這個是整體更改的,包括顏色和文本扛芽。
在AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//tabbar 默認(rèn)的渲染顏色為藍(lán)色 這里是將默認(rèn)的渲染顏色改為紅色 包括圖片和字體
[[UITabBar appearance] setTintColor:[UIColor redColor]];
return YES;
}