2014-10-09 44 views
7

我试图让我的TabBar透明的,我已经搜查,但所有我发现了导致部分并没有完全透明tabBars文章,有些是为iOS 5等在iOS的8

完全透明UITabBar我想做到这一点所看到的草图3:

enter image description here

什么是实现这一目标的最简单的方法?

我想这样做的:

// Make the tabBar transparent 
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor]; 
self.tabBarController.tabBar.translucent = YES; 

但结果不完全完美!

enter image description here

真的很感谢帮助:)

真诚, 埃里克

更新

// Make the tabBar transparent 
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]]; 
self.tabBarController.tabBar.translucent = YES; 

回答

22

您是否尝试过的barTintColor

[[UITabBar appearance] setBarTintColor:[UIColor clearColor]]; 
[[UITabBar appearance] setBackgroundImage:[UIImage new]]; 

这应该做的伎俩。

+0

同样的结果与我把我的更新问题的代码:/ - 我把这个代码在viewWillAppear中的方法,是正确的? – Erik 2014-10-09 13:26:08

+0

@Erik'viewWillAppear:'为时已晚。尝试把它放在AppDelegate的'application:didFinishLaunchingWithOptions:'中,看看是否有帮助。 – 2014-10-09 17:12:26

+0

@JohannesFagrenkrug不幸的是,我的更新中的代码与didFinishLaunchingWithOptions中的代码相同: – Erik 2014-10-09 17:18:17

6

您需要继承的UITabBarController,并在viewdidload:,你应该把这个代码:

CGRect rect = CGRectMake(0, 0, 1, 1); 
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 1.0); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); 
CGContextFillRect(context, rect); 
UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
[self.tabBar setBackgroundImage:transparentImage]; 
[self.tabBar setShadowImage:transparentImage];  
// self.tabBar.alpha = 0.0; 
+1

我没有使用子类,但'setShadowImage'是我的问题的秘密,+1 :) – Olie 2015-06-02 23:52:26

19

雨燕3.0

...在AppDelegate中的didFinishLaunchingWithOptions调用此代码

let tabBar = UITabBar.appearance() 
tabBar.barTintColor = UIColor.clear 
tabBar.backgroundImage = UIImage() 
tabBar.shadowImage = UIImage() 

结果将是每个UITabBar的透明背景。

+0

在互联网上经历了很多不同的事情和解决方案之后,这使得tabbar'半透明',但现在它感觉它太半透明,完全没有模糊。我相信它的tabBar。backgroundImage = UIImage()导致这一点。任何额外的帮助,可以产生良好的模糊效果,而不是完全透明? – c0d3Junk13 2017-11-08 18:55:02

0

这种简单的解决方案固定我的问题:

let size = CGSize(width: tabBar.bounds.size.width, 
         height: tabBar.bounds.size.height) 
tabBar.backgroundImage = UIImage.jotImage(with: UIColor.clear, size: size)