【问题标题】:How to remove the glossy highlight on selected UITabBarItem in iOS?如何在 iOS 中删除选定的 UITabBarItem 上的光泽突出显示?
【发布时间】:2013-07-05 11:49:06
【问题描述】:

默认情况下,在 UITabbar 中,选定的 UITabBarItem 上有一个光泽突出显示。

是否可以去除光泽高光遮罩?

谢谢。

【问题讨论】:

    标签: iphone ios ipad


    【解决方案1】:
    [[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc] init]];
    

    像魅力一样工作!

    【讨论】:

    • 很好的答案,但请注意,这将影响所有 UITabBar,甚至是子类。
    【解决方案2】:
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage {anImage}]]
    

    这会影响您使用的每个标签栏(甚至是子类)

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

    也许您甚至可以使用全透明图像,或 1px*1px 的图像。

    【讨论】:

    【解决方案3】:

    如果您使用自定义图像自定义标签栏项目,您可以这样做。 我通过将背景图像添加到标签栏来自定义标签栏项目,其中所有标签都已绘制,一个标签处于选中状态,其他标签处于未选中状态。在每个 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.
    
    }  
    

    也许你会对这个感兴趣:)

    【讨论】:

    • 在 UIViewController 中,它正在实现您的标签栏控制器的委托。您需要每个选项卡栏项目的整个选项卡栏面板的图像,代表当前项目图片处于选中状态,其他处于默认状态。根据选中的标签索引,在 - (void)customizeTabBar 中替换背景
    • 好答案!为我工作
    【解决方案4】:

    根据 Apple 的文档,您可以实施:

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

    这是一个UITabBar方法

    Here´s the link.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 2011-08-04
      相关资源
      最近更新 更多