iOS 8 中完全透明的 UITabBar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26279478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Completely transparent UITabBar in iOS 8
提问by Erik
I'm trying to make my tabBar transparent, I've searched but all I found was articles resulting in partly and not fully transparent tabBars and some were for IOS 5, etc.
我试图让我的 tabBar 透明,我已经搜索过,但我发现的只是导致部分而不是完全透明的 tabBar 的文章,有些是针对 IOS 5 等的。
I would like to accomplish this as seen in Sketch 3:
我想完成这一点,如 Sketch 3 所示:
What's the easiest way to accomplish this?
实现这一目标的最简单方法是什么?
I thought of doing this:
我想这样做:
// Make the tabBar transparent
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
self.tabBarController.tabBar.translucent = YES;
but that result wasn't exactly perfect:
但结果并不完美:
Really appreciate help!:)
真的很感谢帮助!:)
Sincerely, Erik
真诚的,埃里克
Update
更新
// Make the tabBar transparent
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
self.tabBarController.tabBar.translucent = YES;
回答by Johannes Fahrenkrug
Have you tried the barTintColor
?
你试过barTintColor
吗?
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
That should do the trick.
这应该够了吧。
回答by user3378170
Swift 3.0
斯威夫特 3.0
... call this code in the AppDelegate's didFinishLaunchingWithOptions
...在 AppDelegate 的 didFinishLaunchingWithOptions 中调用此代码
let tabBar = UITabBar.appearance()
tabBar.barTintColor = UIColor.clear
tabBar.backgroundImage = UIImage()
tabBar.shadowImage = UIImage()
The result will be a transparent background for every UITabBar.
结果将是每个 UITabBar 的透明背景。
回答by Lior L.
You need to subclass the UITabBarController and in the viewdidload:
you should put this code:
您需要继承 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;
回答by Adela Toderici
This easy solution fixed my problem:
这个简单的解决方案解决了我的问题:
let size = CGSize(width: tabBar.bounds.size.width,
height: tabBar.bounds.size.height)
tabBar.backgroundImage = UIImage.jotImage(with: UIColor.clear, size: size)