Completely transparent UITabBar in iOS 8

Eri*_*rik 14 objective-c transparent uitabbarcontroller uitabbar ios

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.

I would like to accomplish this as seen in Sketch 3:

enter image description here

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;
Run Code Online (Sandbox Code Playgroud)

but that result wasn't exactly perfect:

enter image description here

Really appreciate help!:)

Sincerely, Erik

Update

// Make the tabBar transparent
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
self.tabBarController.tabBar.translucent = YES;
Run Code Online (Sandbox Code Playgroud)

Joh*_*rug 29

Have you tried the barTintColor?

[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
Run Code Online (Sandbox Code Playgroud)

That should do the trick.

  • 我将此与Lior的回答结合使用,setShadowImage是让黑线消失的伎俩. (2认同)

use*_*170 29

Swift 3.0

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

let tabBar = UITabBar.appearance()
tabBar.barTintColor = UIColor.clear
tabBar.backgroundImage = UIImage()
tabBar.shadowImage = UIImage()
Run Code Online (Sandbox Code Playgroud)

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


小智 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;
Run Code Online (Sandbox Code Playgroud)

  • 我没有使用子类,但是 `setShadowImage` 是我问题的秘密,+1:) (2认同)