I have a UIToolbar that has a white tint, with a bar button item, followed by some flexible space, followed by another bar button item. I would like to make the toolbar completely clear so that I can see what is under the flexible space (I don't care about seeing what is behind the buttons). Is there a way to do this? I have tried setting the toolbar to translucent, but that does not make it completely clear.

- 37,241
- 25
- 195
- 267

- 1,672
- 4
- 22
- 38
-
1possible duplicate of [Transparent UIToolbar](http://stackoverflow.com/questions/6250439/transparent-uitoolbar) – trojanfoe Aug 21 '12 at 15:48
-
http://stackoverflow.com/a/7027807/653513 – Rok Jarc Aug 21 '12 at 16:07
-
Hey guys, sorry about the duplicate. I didn't notice the other one. Please close the question and mark as duplicate. – Kyle Rosenbluth Aug 21 '12 at 16:49
8 Answers
[self.toolbar setBackgroundImage:[UIImage new]
forToolbarPosition:UIToolbarPositionAny
barMetrics:UIBarMetricsDefault];
[self.toolbar setBackgroundColor:[UIColor clearColor]];

- 1,596
- 16
- 13
-
This approach was the only one working when inserting a transparent UIToolbar as a NavigationItem.TitleView. – Miros Jul 16 '13 at 12:53
-
3
-
@Chris, I noticed the same thing. Not sure how to fix it. Luckily i'm needing to do this in a popup where the view's border color is black. So i've just moved the toolbar up so the shadow (or whatever it is) gets lost in the border. – Andrew Mar 19 '14 at 16:25
-
10@Andrew - I used setShadowImage:forToolbarPosition: to set the shadow image to [[UIImage alloc] init] – Chris Mar 20 '14 at 22:04
-
Note: if a toolbar is added to the scene, it is *not* referenced by self.navigationController.toolbar - this is the default one owned by the navigationController (see http://stackoverflow.com/a/8753847/481207). – Matt Dec 09 '14 at 19:45
-
Swift Version .: self.toolbar.isTranslucent = true self.toolbar.setBackgroundImage(UIImage(), forToolbarPosition: UIBarPosition.any, barMetrics: UIBarMetrics.default) self.toolbar.setShadowImage(UIImage(), forToolbarPosition: UIBarPosition.any) – Vivek Dec 26 '17 at 12:16
Subclass UIToolbar, and implement the below method:
- (void)drawRect:(CGRect)rect
{
[[UIColor colorWithWhite:0 alpha:0.6f] set]; // or clearColor etc
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
}
see more details here

- 1
- 1

- 30,739
- 9
- 69
- 102
-
-
Close the question and mark it a duplicate of the one you linked to. – trojanfoe Aug 21 '12 at 15:55
-
This is indeed the correct way to do it. It is quite an annoyance though that it cannot be customized without subclassing... – MikeS Aug 21 '12 at 17:00
-
You can customize it without subclassing - see @NANNAV's point below. More elegant IMHO, mind you -1 doesn't fit into UIBarStyle's enum in `UIInterface.h`. But what could possibly go wrong? :S – Scott Corscadden Nov 13 '13 at 16:56
-
set toolbarStyle -1 like this
tools.barStyle = -1; // clear background

- 4,875
- 4
- 32
- 50
-
-
This was the only approach that worked for me with Xcode 13 and iOS 15. But as the other postings mention it leaves a 1 px dark bar at the top to the toolbar – LancDec Mar 10 '22 at 19:04
-
This works well in light mode but not dark mode, will have to use the recommended (with setShadow too) to completely fix this – Tj3n Jun 02 '22 at 06:58
-
Xcode 15 beta 5 -> Cannot assign value of type 'Int' to type 'UIBarStyle', can't seem to hack my way around it... – benc Aug 21 '23 at 19:24
Hacky, sorry, but the only way I've found so far that reliably works in both iOS 7 and iOS 6 is to do this:
[[toolbar.subviews objectAtIndex:0] removeFromSuperview];

- 4,106
- 3
- 36
- 44
-
1
-
Thanks @Tuss. In my defence, in iOS 6, `firstObject` was a private API. ;) – Danyal Aytekin Sep 29 '16 at 17:41
If you want a global solution take advantage of the UIAppearance
proxy:
UIToolbar *toolbarAppearance = [UIToolbar appearance];
[toolbarAppearance setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

- 19,175
- 22
- 126
- 148
There is a solution in @ievgen answer in Swift 5.1
toolbar.setBackgroundImage(UIImage(), forToolbarPosition: .any, barMetrics: .default)
toolbar.backgroundColor = .clear
If you want to clear the separator gray line
toolbar.setShadowImage(UIImage(), forToolbarPosition: .any)

- 1,656
- 1
- 16
- 36
It can be done without subclassing in iOS 6+ with setting the property translucent
to `YES.
This will not work in iOS 5 in below. Here's how it can be done without subclassing toolbar:
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[self.toolbar setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];

- 4,057
- 7
- 37
- 45
Swift 3 version of accepted answer:
self.toolbar.isTranslucent = true
self.toolbar.setBackgroundImage(UIImage(),
forToolbarPosition: UIBarPosition.any,
barMetrics: UIBarMetrics.default)
self.toolbar.setShadowImage(UIImage(), forToolbarPosition: UIBarPosition.any)

- 99
- 1
- 7