博客> TabBarController里面item选中后图片显示为蓝色
TabBarController里面item选中后图片显示为蓝色
2019-12-11 07:07 评论:0 阅读:1022 wangwei1
ios UITabBarController底部选中图片渲染问题

TabBarController里面item选中后图片显示为蓝色,因为xcode 默认TabBarController item渲染,只需要取消渲染就可以,例如下面的代码:

@interface XTMainViewController () {

 UINavigationController *_nv;

}

@end

NSArray *titles = @[@"首页", @"资讯", @"聊天", @"个人"];
NSArray *imgName = @[@"11", @"22", @"33", @"44"];
for (int i=0; i<self.viewControllers.count; i++) {

    UINavigationController *nvc = self.viewControllers[i];

    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@_normal", imgName[i]]];
   //  UIImageRenderingModeAlwaysOriginal即可取消渲染,让选中的图片背景正常显示
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    UIImage *imageSel = [UIImage imageNamed:[NSString stringWithFormat:@"%@_select", imgName[i]]];
  //  UIImageRenderingModeAlwaysOriginal即可取消渲染,让选中的图片背景正常显示
    imageSel = [imageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    nvc.tabBarItem = [[UITabBarItem alloc] initWithTitle:titles[i] image:image selectedImage:imageSel];
    _nv = self.viewControllers[2];

}
收藏
0
sina weixin mail 回到顶部