Last active
August 23, 2017 15:15
-
-
Save yelled3/6881965 to your computer and use it in GitHub Desktop.
UINavigationBar with totally transparent background (iOS6 + iOS7 tested)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface MyCustomNavigationBar : UINavigationBar | |
@end | |
@implementation MyCustomNavigationBar | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
[self setup]; | |
} | |
return self; | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder { | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
[self setup]; | |
} | |
return self; | |
} | |
- (void)setup { | |
[self setupBackground]; | |
} | |
- (void)setupBackground { | |
self.backgroundColor = [UIColor clearColor]; | |
self.tintColor = [UIColor clearColor]; | |
// make navigation bar overlap the content | |
self.translucent = YES; | |
self.opaque = NO; | |
// remove the default background image by replacing it with a clear image | |
[self setBackgroundImage:[self.class maskedImage] forBarMetrics:UIBarMetricsDefault]; | |
// remove defualt bottom shadow | |
[self setShadowImage: [UIImage new]]; | |
} | |
+ (UIImage *)maskedImage { | |
const float colorMask[6] = {222, 255, 222, 255, 222, 255}; | |
UIImage *img = [UIImage imageNamed:@"nav-white-pixel-bg.jpg"]; | |
return [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 46: float -> CGFloat