简体   繁体   中英

How to remove the glossy highlight on selected UITabBarItem in iOS?

By default in the UITabbar, there is a glossy highlight on the selected UITabBarItem.

Is it possible to remove the glossy highlight mask ?

Thanks.

[[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc] init]];

奇迹般有效!

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage {anImage}]]

this has effect on every tabbar you use (even the subclassed ones)

If you use an image here that has the same colour as your tabbar background, you wont see an indicator.

Maybe you can even use an full transparent image, or an image that's 1px*1px.

In case if you are customizing tab bar items with custom images, you may do such thing. I made customizing tab bar items by adding background image to tab bar with all tabs drawn, one tab in selected state, and others in unselected state. In each didSelectViewController I change background image. Than, I bring background image view to front, and add custom labels with needed title.

Result: I have customized tab bar with no glossy effect. Interesting is that UITabBarButtons are under background image, but still selectable.

The code is something like that:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    [self customizeTabBar];
}

- (void)customizeTabBar {

    NSString *imageName = [NSString stringWithFormat:@"tabbg%i.png", tabBarCtrl.selectedIndex + 1];

    for(UIView *view in tabBarCtrl.tabBar.subviews) {  
        if([view isKindOfClass:[UIImageView class]]) {  
            [view removeFromSuperview];  
        }  
    }  
    UIImageView *background = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]] autorelease];
    [tabBarCtrl.tabBar insertSubview:background atIndex:0]; 
    [tabBarCtrl.tabBar bringSubviewToFront:background];
        //if needed, here must be adding UILabels with titles, I didn't need it.

}  

Maybe you will be interested about this :)

According to Apple´s Documentation you can implement :

(void)setFinishedSelectedImage:
      (UIImage *)selectedImage withFinishedUnselectedImage:
      (UIImage *)unselectedImage

Which is a UITabBar method

Here´s the link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM