iOS开发_tabBar图片渲染问题

在使用tabBarViewController的时候,会遇到在tabBar中显示的图片和颜色被渲染成为蓝色的问题。
解决方法如下:
1、关闭图片的自动渲染

UIImage *selectImg = [UIImage imageNamed:[NSString stringWithFormat:@"icon.png"]];
selectImg = [selectImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
VC.tabBarItem.selectedImage=selectImage;

这种方法可以单独将图片设置成为禁止进行自动渲染。

2、整体设置图片的颜色(可分被选择状态和正常状态)

UITabBarItem *itm=[UITabBarItem appearance];

[itm setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor groupTableViewBackgroundColor]} forState:UIControlStateNormal];

[itm setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];

3、将系统渲染的颜色进行更改
这个是整体更改的,包括颜色和文本。
在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //tabbar 默认的渲染颜色为蓝色  这里是将默认的渲染颜色改为红色 包括图片和字体
    [[UITabBar appearance] setTintColor:[UIColor redColor]];
    return YES;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容