简体   繁体   中英

How to create translucent (with content behind it) UITabBar

I have subclassed UITabBar and overriden drawRect: method to make it transparent (and make it look like I need to). Problem I am having is that the view added to UITabBarController does not cover whole screen but ends 49 pixels above bottom, so even tho I have transparent tabbar, I can't see thing behind it.

Is there proper way how I can set size of UIView inside UITabBarController to cover entire screen?

PS:I know it is not good idea to show content behind tabbar. I do not want to show any content there, just art, that is specific to each View and needs to be visible through tabbar.

If you want to have content behind the UITabBar , I see two options:

  • Don't use UITabBarController – This will definitely work, because you can position the views as you want and it is not so difficult to implement it.

  • Try turning off clipsToBounds on the view and place some view out of his bounds.

     // UIViewController contained in UITabBarController: self.view.clipsToBounds = NO; UIView *viewBehindTabBar = [[UIView alloc] init]; viewBehindTabBar.frame = CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 49); // autoresizing mask, background color, ... [self.view addSubview:viewBehindTabBar]; 

You can simply create a category of UITabBar or UITabBarController and set It's Alpha .

Something Like :-

@implementation UITabBarController (Translucent)
- (void)createImage
{
     [self.tabBar setAlpha:0.1];
}
@end

You can set Alpha even in Drawrect .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM