How to create translucent (with content behind it) UITabBar

我怕爱的太早我们不能终老 提交于 2020-01-02 08:24:26

问题


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.


回答1:


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



回答2:


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 .



来源:https://stackoverflow.com/questions/15431795/how-to-create-translucent-with-content-behind-it-uitabbar

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