关于objective C:iOS 8 中完全透明的 UITabBar

Completely transparent UITabBar in iOS 8

我正在尝试使我的 tabBar 透明,我已经搜索过,但我发现的只是导致部分透明和不完全透明的 tabBar 的文章,有些是针对 IOS 5 等的。

我想像 Sketch 3 中看到的那样完成这个:

enter image description here

最简单的方法是什么?

我想过这样做:

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

但结果并不完美:

enter image description here

非常感谢帮助!:)

真诚地,
埃里克

更新

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


你试过barTintColor吗?

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

那应该可以解决问题。


斯威夫特 3.0

... 在 AppDelegate\\'s didFinishLaunchingWithOptions 中调用此代码

1
2
3
4
let tabBar = UITabBar.appearance()
tabBar.barTintColor = UIColor.clear
tabBar.backgroundImage = UIImage()
tabBar.shadowImage = UIImage()

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


您需要继承 UITabBarController 并在 viewdidload: 中放置以下代码:

1
2
3
4
5
6
7
8
9
10
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;