Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Created October 15, 2013 06:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-mcnally/6987297 to your computer and use it in GitHub Desktop.
Save j-mcnally/6987297 to your computer and use it in GitHub Desktop.
Swizzle Color Transparent
//
// UINavigationBar+DarkTint.h
//
// Created by Justin McNally on 10/15/13.
//
//
#import <UIKit/UIKit.h>
@interface UINavigationBar (DarkTint)
@property CALayer *colorLayer;
@end
//
// UINavigationBar+DarkTint.m
//
// Created by Justin McNally on 10/15/13.
//
//
#import "UINavigationBar+DarkTint.h"
#import <objc/runtime.h>
@implementation UINavigationBar (DarkTint)
@dynamic colorLayer;
static CGFloat const kSpaceToCoverStatusBars = 20.0f;
- (void)swizlayoutSubviews {
[self swizlayoutSubviews];
if (self.colorLayer == nil) {
self.colorLayer = [[CALayer alloc] init];
self.colorLayer.opacity = .85;
[self.layer addSublayer:self.colorLayer];
self.colorLayer.backgroundColor = [[UIColor colorWithRed:.26 green:.50 blue:.76 alpha:1] CGColor];
}
NSLog(@"%@", self.colorLayer);
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];
NSLog(@"Color Layer = %@", self.colorLayer);
}
}
-(void) setColorLayer:(CALayer *)colorLayer {
objc_setAssociatedObject(self, @"colorLayer", colorLayer, OBJC_ASSOCIATION_RETAIN);
}
-(CALayer *) colorLayer {
return objc_getAssociatedObject(self, @"colorLayer");
}
+(void) load {
Method original, swizzled;
original = class_getInstanceMethod(self, @selector(layoutSubviews));
swizzled = class_getInstanceMethod(self, @selector(swizlayoutSubviews));
method_exchangeImplementations(original, swizzled);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment