Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 选项卡栏图标显示不正确_Ios_Iphone_Tabbar - Fatal编程技术网

Ios 选项卡栏图标显示不正确

Ios 选项卡栏图标显示不正确,ios,iphone,tabbar,Ios,Iphone,Tabbar,在我的应用程序中,有一个带有四个选项卡的选项卡栏。我将选项卡栏图标资源50x50添加到Images.xcsets中。但我发现其中一个icosn显示不正确,如下图所示: - (void)customTabBarItems{ self.tabBar.superview.backgroundColor = [UIColor whiteColor]; NSArray *items = self.tabBar.items; NSArray *normalImgs = @[@"ta

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

- (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
当我将第一个图标更改为另一个图标时,看起来还可以,但我想使用此图标:


问题似乎出在颜色上。“着色颜色”更改图像可见像素的颜色,因此它通常用于更改具有透明度的图像的颜色。您的图像似乎没有透明背景,所以淡色使其成为整个蓝色。请检查您的图像源。如果图像质量良好,还有一种可能的解决方案-在设置图像之前使用图像的渲染模式:

UIImage *toSet = [yourImage  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

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


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


作为对以后文章的一个提示:正确格式化代码。如果你这样做,人们的反应会更好。@steven试着正确地发帖……HUI白色部分是透明的还是实际上是白色的?@Quentin Hayot该部分是透明的。谢谢,我将渲染模式更改为图像集中的模板图像,但它不起作用。并且图像的背景是透明的。