标签栏图标显示不正确

时间:2015-05-07 09:26:26

标签: ios iphone tabbar

在我的应用程序中有一个带有四个选项卡的Tabbar。我将标签栏图标资源(50x50)添加到Images.xcassets。但我发现其中一个icosn显示不正确,如下图所示:

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

当我将第一个图标更改为另一个时,似乎没问题,但我想使用这个:

tab image

3 个答案:

答案 0 :(得分:1)

似乎问题是色彩。色调颜色改变图像可见像素颜色,因此它通常用于改变具有透明度的图像颜色。看起来你的图像没有透明背景,所以色调使它全蓝。请检查您的图像来源。如果您的图像良好,还有一种可能的解决方案 - 在设置之前使用图像的渲染模式:

UIImage *toSet = [yourImage  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

答案 1 :(得分:0)

最近的答案是将图标的渲染模式更改为原始图像:

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

答案 2 :(得分:-1)

必须将图标的渲染模式更改为原始图像

enter image description here