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

我已经subclassed UITabBar和重写drawRect:方法使其透明(并使其看起来像我需要)。 我遇到的问题是添加到UITabBarController视图不覆盖整个屏幕,但结束底部49像素,所以即使我有透明的tabbar,我看不到它背后的东西。

有没有适当的方式,我可以在UITabBarController里面设置UIView的大小来覆盖整个屏幕?

PS:我知道在tabbar后面显示内容不是个好主意。 我不想在那里显示任何内容,只是艺术,这是特定于每个视图,需要通过tabbar可见。

如果你想拥有UITabBar背后的内容,我看到两个select:

  • 不要使用UITabBarController – 这肯定会起作用,因为您可以根据需要定位视图,并且实现它并不困难。

  • 尝试closuresclipsToBounds上的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]; 

你可以简单地创build一个UITabBar或UITabBarController类别并设置它的Alpha

就像是 :-

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

甚至可以在Drawrect中设置Alpha。