Skip to content

Instantly share code, notes, and snippets.

@zakol
Created January 23, 2015 09:02
Show Gist options
  • Save zakol/82798fc51a0277563eea to your computer and use it in GitHub Desktop.
Save zakol/82798fc51a0277563eea to your computer and use it in GitHub Desktop.
Custom color for iOS status bar text
#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