开发者

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

开发者 https://www.devze.com 2023-03-29 08:50 出处:网络
By default in the UITabbar, there is a glossy highlight on the selected UITabBarItem. Is it possible to remove the glos开发者_开发知识库sy highlight mask ?

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

Is it possible to remove the glos开发者_开发知识库sy highlight mask ?

Thanks.


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

Works like a charm!


[[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.

0

精彩评论

暂无评论...
验证码 换一张
取 消