如何删除iOS中所选UITabBarItem上的光泽高亮?

use*_*015 13 iphone ipad ios

默认情况下,在UITabbar中,所选UITabBarItem上有一个光泽高亮显示.

是否可以去除光泽的高光蒙版?

谢谢.

小智 60

[[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc] init]];
Run Code Online (Sandbox Code Playgroud)

奇迹般有效!

  • 有人应该将此标记为正确.. <3 (3认同)

Jac*_*cco 6

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage {anImage}]]
Run Code Online (Sandbox Code Playgroud)

这对你使用的每个tabbar都有影响(甚至是子类的)

如果您在此处使用与标签栏背景颜色相同的图像,则不会看到指示符.

也许你甚至可以使用完全透明的图像,或者是1px*1px的图像.

  • 使用http://ioscodesnippet.tumblr.com/post/9247898208/creating-a-placeholder-uiimage-dynamically-with-color创建清晰图像.效果很好. (2认同)

Dmi*_*kov 5

如果您使用自定义图像自定义标签栏项目,您可以执行此类操作.我通过向选项卡栏添加背景图像来自定义标签栏项目,其中所有选项卡都已绘制,一个选项卡处于选定状态,其他选项卡处于未选定状态.在每个didSelectViewController中,我更改了背景图像.然后,我将背景图像视图添加到前面,并添加带有所需标题的自定义标签.

结果:我有自定义标签栏没有光泽效果.有趣的是UITabBarButtons在背景图像下,但仍然可以选择.

代码是这样的:

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

}  
Run Code Online (Sandbox Code Playgroud)

也许你会对此感兴趣:)

  • 在UIViewController <UITabBarControllerDelegate>中,它实现了标签栏控制器的委托.每个标签栏项目需要整个标签栏面板的图像,表示处于选定状态的当前项目图片,以及其他处于默认状态的图片.根据选定的选项卡索引,后台将替换为 - (void)customizeTabBar (2认同)