美文网首页
iOS开发_tabBar图片渲染问题

iOS开发_tabBar图片渲染问题

作者: DDB_CS | 来源:发表于2017-11-08 16:27 被阅读24次

在使用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;
}

相关文章

网友评论

      本文标题:iOS开发_tabBar图片渲染问题

      本文链接:https://www.haomeiwen.com/subject/hkdymxtx.html