如何在UITabBarController中获得完全透明的TabBar [英] How to get a fully transparent TabBar in UITabBarController

查看:748
本文介绍了如何在UITabBarController中获得完全透明的TabBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have spent the last few hours trying to get the TabBar in a UITabBarController fully transparent (clear background). I use a custom subclass of the UITabBarController and I managed to change the tintColor, the alpha, but the background color definitely remains the one defined in IB. Thanks for your help, I'm getting crazy...

推荐答案

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

Here is one way to accomplish that.

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.

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

And here is a link to a tutorial I found very useful in changing the tab bar's background. You can play around with the code and costomize it to your liking.

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

编辑:

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

As far as setting the background color of tabbar to transparent or clear color, you have two ways. One is the image which I explained and you didn't like. The other one is to set the background of tabbar in its supper view. Something along the following line.

tabBar.superview.backgroundColor = [UIColor clearColor];

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

This way you reach behind the tabbar and change that black background to whatever you want.

编辑1:

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

sorry for delay in adding the solution for ios 7. below is the method you need to change the background color of the tabbar in ios 7.

只需在 ViewDidLoad 方法中添加以下代码行,它就会做神奇。

just add the following line of code inside your ViewDidLoad method and it will do the magic.

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

希望这会有所帮助。:)

hope this helps.:)

这篇关于如何在UITabBarController中获得完全透明的TabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆