Skip to content

Instantly share code, notes, and snippets.

@mkll
Last active April 18, 2016 03:33
Show Gist options
  • Save mkll/9474673 to your computer and use it in GitHub Desktop.
Save mkll/9474673 to your computer and use it in GitHub Desktop.
How to draw a transparent UIToolbar or UINavigationBar in iOS7
/*
Setting translucent to YES on the navigation bar does the trick, due to a behavior discussed in the UINavigationBar documentation. I'll report here the relevant fragment:
If you set this property to YES on a navigation bar with an opaque custom background image, the navigation bar will apply a system opacity less than 1.0 to the image.
*/
// Transparent UINavigationBar
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
// Transparent UIToolbar
[self.toolbar setBackgroundImage:[UIImage new] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[self.toolbar setShadowImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny];
@adamkaplan
Copy link

You could hack around that by creating a single pixel PNG image with #7919CA / 0.8, making it a resizable UIImage and setting that as the background image instead. You can even do that in code pretty easily with CoreGraphics and UIGraphicsContext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment