去除UITabBarController 中的文字 图片蓝色渲染

在tabBarcontroller的.m文件中


+ (void)initialize
{
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}

去除图片的蓝色渲染效果: 在传入的image时 后边加上mageWithRenderingMode:UIImageRenderingModeAlwaysOriginal

 vc.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

例如:

- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController * nv = [[UINavigationController alloc]initWithRootViewController:vc];
    
    
    [self addChildViewController:nv];
    
    
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,198评论 4 61
  • 為你的人生創造最崇高、最宏偉的願景,因為你將成為你所相信的。 Create the highest, grande...
    黑木黑木阅读 152评论 0 2
  • 其实我从来没有想到我会做微商!说真的,我不缺钱养家糊口。只是那段时间特别的迷茫,工作嘛整天就是些挑鸡肋的事,文...
    瑀轩阅读 508评论 0 0
  • 忍不住化身一条固执的鱼,逆着洋流独自游到底。 水的温度几经变化,周遭的压力越来越大。 还要继续这样前行么?机械的摆...
    阿阿阿进阅读 172评论 0 1
  • 村上春树,作为一个著作等身,荣获多项文学大奖(如“耶路撒冷文学奖”,“安徒生文学奖”,“弗朗茨卡夫卡奖”等)的写作...
    映日红阅读 412评论 0 1