Skip to content

Instantly share code, notes, and snippets.

@zakol
Created January 23, 2015 09:02
Show Gist options
  • Select an option

  • Save zakol/82798fc51a0277563eea to your computer and use it in GitHub Desktop.

Select an option

Save zakol/82798fc51a0277563eea to your computer and use it in GitHub Desktop.

Revisions

  1. Dawid created this gist Jan 23, 2015.
    34 changes: 34 additions & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #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