Skip to content

Instantly share code, notes, and snippets.

@Adrian2112
Created November 21, 2013 22:43
Show Gist options
  • Save Adrian2112/7591168 to your computer and use it in GitHub Desktop.
Save Adrian2112/7591168 to your computer and use it in GitHub Desktop.
UINavigationBar with color
#import "NavigationBarColor.h"
@interface NavigationBarColor ()
@property (nonatomic, strong) CALayer *colorLayer;
@end
@implementation NavigationBarColor
static CGFloat const kDefaultColorLayerOpacity = 0.5f;
static CGFloat const kSpaceToCoverStatusBars = 20.0f;
- (void)setBarTintColor:(UIColor *)barTintColor {
[super setBarTintColor:barTintColor];
if (self.colorLayer == nil) {
self.colorLayer = [CALayer layer];
self.colorLayer.opacity = kDefaultColorLayerOpacity;
[self.layer addSublayer:self.colorLayer];
}
self.colorLayer.backgroundColor = barTintColor.CGColor;
}
- (void)layoutSubviews {
[super layoutSubviews];
if (self.colorLayer != nil) {
self.colorLayer.frame = CGRectMake(0, 0 - kSpaceToCoverStatusBars, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + kSpaceToCoverStatusBars);
[self.layer insertSublayer:self.colorLayer atIndex:1];
}
}
@end
...
- (id)init {
self = [super initWithNavigationBarClass:[NavigationBarColor class] toolbarClass:nil];
if(self) {
...
}
return self;
}
..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment