Created
January 23, 2015 09:02
-
-
Save zakol/82798fc51a0277563eea to your computer and use it in GitHub Desktop.
Custom color for iOS status bar text
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> | |
#import <objc/runtime.h> | |
@interface UIStatusBar : NSObject @end | |
@implementation UIStatusBar (CustomColor) | |
+ (void)load | |
{ | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
Class class = [self class]; | |
SEL originalSelector = @selector(foregroundColor); | |
SEL swizzledSelector = @selector(s_foregroundColor); | |
Method originalMethod = class_getInstanceMethod(class, originalSelector); | |
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); | |
BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); | |
if (didAddMethod) | |
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); | |
else | |
method_exchangeImplementations(originalMethod, swizzledMethod); | |
}); | |
} | |
- (UIColor*)s_foregroundColor | |
{ | |
return [UIColor redColor]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment