Black background on transparent UITabBar

Josh

I am trying to make a blurred background the UITabBar for my UITabViewController, and the idea is to have it be blurred and transparent so that the views underneath can be seen scrolling by.

Unfortunately I cannot for the life of me get the tab bar to be transparent. No matter what I do, there is always some black background to the tab bar that prevents the underlying view controllers from showing through.

If I change the alpha of the UITabBar to something low I can see that the tableview is indeed behind it, however you can see that the UITabBar has some sort of background to it that is preventing the tableview from fully showing through (and I don't want to bar button items to be invisible, just the tab bar background).

alpha 0.3 tab bar

How can this be?

In the custom tab bar's view did load I have:

self.tabBar.translucent = true
self.tabBar.alpha = 0.3
self.tabBar.backgroundColor = UIColor.clearColor().colorWithAlphaComponent(0.0)
self.tabBar.layer.backgroundColor = UIColor.clearColor().colorWithAlphaComponent(0.0).CGColor
self.tabBar.backgroundImage = nil
self.tabBar.shadowImage = nil

and in the AppDelegate I have:

UITabBar.appearance().barTintColor = UIColor.clearColor()
UITabBar.appearance().tintColor = kColorAccent
UITabBar.appearance().translucent = true
UITabBar.appearance().translucent = true
UITabBar.appearance().backgroundColor = UIColor.clearColor()
UITabBar.appearance().backgroundImage = nil
UITabBar.appearance().layer.backgroundColor = UIColor.clearColor().CGColor
UITabBar.appearance().shadowImage = nil

...yeah It's excessive but I want to try everything.

Any ideas on what to do?

SwiftArchitect

Make a UITabBar transparent

Assign a clear image to its backgroundImage. You can use a 1x1 clear.png, or create one programmatically:

self.backgroundImage = UIImage.imageWithColor(UIColor.clearColor())

This will make the UITabBar transparent:

Transparent

Add a blur effect

Insert a UIVisualEffectView as the rearmost subview.

let frost = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
frost.frame = self.bounds
self.insertSubview(frost, atIndex: 0)

This will insert a UIBlurEffect (frost):

Frost

Example

Frosty toolbar


  1. Set the Custom Class for the UITabBar of the Tab Bar Controller to FrostyTabBar.
  2. You have a few options to supply a clearColor image. You can create a clear.png image with an alpha of 0. A programmatic elegant solution is described here.
  3. If using a clear.png, assign it to the Background Image in the Attribute Inspector: enter image description here
  4. In Interface Builder, pick Style: Default & Translucent.
  5. Once you take control of the background blur with a UIVisualEffectView, you can in turn supply any UIVisualEffect you so desire.

The entire FrostyTabBar class looks like this:

import UIKit

class FrostyTabBar: UITabBar {
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        let frost = UIVisualEffectView(effect: UIBlurEffect(style: .light))
        frost.frame = bounds
        frost.autoresizingMask = .flexibleWidth
        insertSubview(frost, at: 0)
    }
}

► Find this solution on GitHub and additional details including a 1x1 clear.png on Swift Recipes.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Set the background of UILabel to transparent black

Transparent view background turns black

Transparent AlertDialog has black background

Transparent spritesheet has black background

Unity Transparent Background Shows As Black

Transparent UITabBar

PHP GD - transparent PNG black background

SVG clipPath showing black background with transparent fill

transparent image background change to black with Jimp

WPF Bitmap transparent background turns black

clip-path: Black background instead of transparent

iOS app icon with transparent background showing black background on device

Opacity and grayscale filter of background image. Making it black and white and transparent

Android TV: unfocused image contains black transparent background?

How to remove a black background from an image and make that transparent using opencv?

How to draw a rectangle with black border and background transparent on Imageview?

PHP - Black background after resizing transparent png and gif

LibGDX. Android. Black background on transparent DecalSprites

Actionbar Styling: Transparent Background, Hidden Title Text, but Black Icons?

Transparent background showing up as black on api 14-15

iOS UINavigationController after setting background to transparent shows black screen

PHP imagecopy & imagecopymerge changing background from transparent to black

Black background (instead of transparent) after drop shadow in ImageMagick

How to set a black background color for text in transparent windows in C++

Graphics.DrawString renders text with black outline on a transparent background

Layer black & white video over background so black pixels are transparent in FFMPEG

Completely transparent UITabBar in iOS 8

UITabBar selected background image

Transparent font on transparent background