How to get a fully transparent TabBar in UITabBarController [duplicate]

余生颓废 提交于 2019-12-21 21:25:18

问题


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


回答1:


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/

Edit:

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.

Edit 1:

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.

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.:)



来源:https://stackoverflow.com/questions/18413352/how-to-get-a-fully-transparent-tabbar-in-uitabbarcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!