2011-08-21 82 views

回答

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

如果使用这里的图像具有色彩为您的TabBar背景相同的这对每次使用的TabBar(甚至是子类的)

效果,你不会看到一个指标。

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

+2

使用http://ioscodesnippet.tumblr.com/post/9247898208/creating -a-placeholder-uiimage-dynamic-with-color创建清晰的图像。很棒。 – nh32rg

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. 

} 

也许你会有兴趣了解这个:)

+0

我应该在哪里添加此代码? – chatur

+2

在这个UIViewController 中,它实现了你的标签栏控制器的委托。每个标签栏项目需要整个标签栏面板的图像,表示处于选定状态的当前项目图片,其他处于默认状态。根据选定的标签索引,背景被替换为 - (void)customizeTabBar – Mitya

+0

非常感谢Mitya .. !! – chatur

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

就像一个魅力!

+3

有人应该将此标记为正确。<3 –

+0

优秀的答案,但请注意,这将影响所有UITabBars,即使是子类也是如此。 –

1

根据Apple's文档,你可以实现:

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

这是中的UITabBar一样的方法

Here´s the link.