Search code examples
iosuitabbarcontrolleruitabbar

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?

P.S.: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.


Solution

  • 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];