The image set to UITabBarItem is painted out

Asked 2 years ago, Updated 2 years ago, 104 views

In Xcode, pdf is registered in imageset with Vector.
I'm using that resource as a tab bar image. Display the screen in the presentViewController. If you close the screen, the white part of the image will be painted out.
For the Active tab, when the screen is completely switched, It will return to normal, but if it is not an active tab, It will remain painted out.
Is there any way to prevent it from being painted out?

This is happening on iOS 8 and not on iOS 6.

objective-c pdf

2022-09-30 19:35

1 Answers

It's too late, but...
- In (UIImage*) imageWithRenderingMode: (UIImageRenderingMode) renderingMode; the solution was to set the image created with UIImageRenderingModeAlwaysOriginal to UITabBarItem.

@interface UIImage (ForTabBar)
+ (UIImage*) imageNamedForTabBar: (NSString*) name;
@end

@implementation UIImage (ForTabBar)
+ (UIImage*) imageNameForTabBar: (NSString*)name {
    UIImage* image=[UIImage imageName:name];
    if( [image repliesToSelector:@selector(imageWithRenderingMode:)] {
        return [ imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal ];
    }
    return image;
}
@end


    // Set image on tab bar
    if([controller.tabBarItem responsesToSelector:@selector(initWithTitle:image:selectedImage:)]){
        // If you set the image that you normally read in imageNamed from iOS7,
        // It will be drawn in UIImageRenderingModeAlwaysTemplate mode.
        // If you want to view the original image, use the imageWithRenderingMode function in UIImage to display the image.
        // If not set, it will be painted out.
        controller.tabBarItem=[HDMainTabBarItem alloc]
                                 initWithTitle:title
                                 image: [UIImage imageNameedForTabBar:@"select.png"]
                                 selectedImage: [UIImage imageNamedForTabBar:@"unselect.png"];
    } else{
        UIImage* unselectedImage= [UIImage imageNamedForTabBar:@"unselect.png" ];
        controller.tabBarItem=[HDMainTabBarItem alloc]
                                 initWithTitle:title
                                 image —UnselectedImage
                                 tag:0];
        [controller.tabBarItem]
         setFinishedSelectedImage:unselectedImage
         withFinishedUnselectedImage: [UIImage imageNamedForTabBar:@"select.png"];
    }


2022-09-30 19:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.