如何在UITabBarController中获得完全透明的TabBar

我花了最后几个小时试图让UITabBarController中的TabBar完全透明(清晰的背景)。 我使用UITabBarController的自定义子类,我设法更改了tintColor,alpha,但背景颜色肯定是IB中定义的颜色。 谢谢你的帮助,我疯了……

这是实现这一目标的一种方法。

CGRect frame = CGRectMake(0.0, 0.0, 320, 48);//Setting a Frame. myTabView = [[UIView alloc] initWithFrame:frame];//Making Tab View // not supported on iOS4 UITabBar *tabBarr = [self.tabBar tabBar]; if ([tabBarr respondsToSelector:@selector(setBackgroundImage:)]) { // set it just for this instance [tabBarr setBackgroundImage:[UIImage imageNamed:@"hot-1.png"]]; // set for all // [[UITabBar appearance] setBackgroundImage: ... } else { // ios 4 code here //[tabBarr setBackgroundColor:c]; } //[myTabView setBackgroundColor:c];//Setting Color Of TaBar. [myTabView setAlpha:0.8];//Setting Alpha of TabView. [[self.tabBar tabBar] insertSubview:myTabView atIndex:0];//Inserting Tab As SubView. 

这里有一个指向我发现在更改标签栏背景时非常有用的教程的链接。 您可以随意使用代码并根据自己的喜好进行优化。

http://ios-blog.co.uk/tutorials/how-to-customize-the-tab-bar-using-ios-5-appearance-api/

编辑:

至于将tabbar的背景颜色设置为透明或清晰的颜色,您有两种方法。 一个是我解释过你不喜欢的图像。 另一种是在其晚餐视图中设置tabbar的背景。 沿着以下行的东西。

 tabBar.superview.backgroundColor = [UIColor clearColor]; 

这样,您就可以到达标签栏后面,并将黑色背景更改为您想要的任何内容。

编辑1:

抱歉延迟添加ios 7的解决方案。下面是更改ios 7中tabbar背景颜色所需的方法。

只需在ViewDidLoad方法中添加以下代码行,它就会发挥作用。

 [self.tabBarController.tabBar setBackgroundColor:[UIColor greenColor]]; 

希望这可以帮助。:)