简体   繁体   English

如何创建半透明(背后有内容)UITabBar

[英]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). 我已经将UITabBar子类化并覆盖了drawRect:方法,使其透明(并使其看起来像我需要的那样)。 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. 我遇到的问题是添加到UITabBarController的视图没有覆盖整个屏幕但是在底部上方49个像素,所以即使我有透明的tabbar,我也看不到它背后的东西。

Is there proper way how I can set size of UIView inside UITabBarController to cover entire screen? 有没有正确的方法我可以在UITabBarController中设置UIView的大小来覆盖整个屏幕?

PS:I know it is not good idea to show content behind tabbar. PS:我知道在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. 我不想在那里展示任何内容,只是艺术,这是每个视图特有的,需要通过tabbar显示。

If you want to have content behind the UITabBar , I see two options: 如果你想在UITabBar后面有内容,我会看到两个选项:

  • 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. 不要使用UITabBarController -这肯定会工作,因为只要你想,你可以定位的意见,也不是那么难实现它。

  • Try turning off clipsToBounds on the view and place some view out of his bounds. 尝试在视图上关闭clipsToBounds并将一些视图放在他的边界之外。

     // 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 . 您只需创建一个UITabBar或UITabBarController类别并设置它的Alpha

Something Like :- 就像是 :-

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

You can set Alpha even in Drawrect . 您甚至可以在Drawrect中设置Alpha。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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