0

In my App there is a Tabbar with four tabs. I add the tabbar icon resources (50x50) into the Images.xcassets. But I found that one of the icosn displayed incorrect as the following image:

tab bar image

- (void)customTabBarItems{
    self.tabBar.superview.backgroundColor = [UIColor whiteColor];

    NSArray *items = self.tabBar.items;
    NSArray *normalImgs = @[@"tab_home_normal",@"tab_message_normal",@"tab_order_normal",@"tab_userCenter_normal"];
    NSArray *selectedImgs = @[@"tab_home_selected",@"tab_message_selected",@"tab_order_selected",@"tab_userCenter_selected"];

    for (NSInteger i = 0; i < items.count; i++) {
        UITabBarItem *item = [items objectAtIndex:i];
        NSString *title = titleArr[i];
        UIImage *normalImg = [UIImage imageNamed:normalImgs[i]];
        UIImage *selectImg = [UIImage imageNamed:selectedImgs[i]];
        item.title = title;
        if (isIOS7Later) {
            item.image = normalImg;
            item.selectedImage = selectImg;
        }
        else{
            [item setFinishedSelectedImage:selectImg withFinishedUnselectedImage:normalImg];
        }
    }
}

//set tint color 

- (void)_customAppearance
{
    if (isIOS7Later)
    {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    }

    UIColor * color = [UIColor whiteColor];
    NSDictionary * dict = [NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor];
    [[UINavigationBar appearance] setTitleTextAttributes:dict];

    if (isIOS7Later)
    {
        [[UITabBar appearance] setTintColor:BGCOLOR(21.0, 170.0, 255.0, 1.0)];
    }
    else
    {
        NSDictionary *textAttributesNormal = @{UITextAttributeTextColor: BGCOLOR(179, 179, 179, 1)};
        NSDictionary *textAttributesSelected = @{UITextAttributeTextColor:BGCOLOR(0, 154, 255, 1)};
        [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_select_image"]];
        [[UITabBarItem appearance] setTitleTextAttributes:textAttributesNormal forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:textAttributesSelected forState:UIControlStateSelected];
        [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
        [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_select_image"]];
    }

    [SVProgressHUD setForegroundColor:BGCOLOR(0, 135.0, 231, 1)];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
}

//Images.xcassets

When I changed the first icon to another, it seems ok, but I want to use this one:

tab image

squarefrog
  • 4,750
  • 4
  • 35
  • 64

3 Answers3

1

Seems like the problem is in tint color. Tint color changes image visible pixels color, so it usually uses for changing color of images with transparency. Seems like your image have no transparent background, so tint color makes it whole blue. Please, check your image source. One more possible solution if your image is good - use rendering mode for image before setting it:

UIImage *toSet = [yourImage  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
4esterUA
  • 285
  • 1
  • 2
  • 7
  • Thanks, I change the render mode to Template Image in Image set, but it doesn't work. And the background of the image is transparent. – steven zhan May 07 '15 at 10:03
0

The more recent answer is to change the rendering mode of your icons to original image:

https://stackoverflow.com/a/38560183/3885491

Falco Winkler
  • 1,082
  • 1
  • 18
  • 24
-1

Must change the rendering mode of your icons to original image

enter image description here

Bùi Đức Khánh
  • 3,975
  • 6
  • 27
  • 43