Skip to content

Instantly share code, notes, and snippets.

@obyknovenius
Created April 13, 2017 10:10
Show Gist options
  • Save obyknovenius/a9ee3267d3dd923a4c32f129b023c5d9 to your computer and use it in GitHub Desktop.
Save obyknovenius/a9ee3267d3dd923a4c32f129b023c5d9 to your computer and use it in GitHub Desktop.
#import <objc/runtime.h>
#import <UIKit/UIKit.h>
#import "NSObject+Swizzling.h"
@implementation NSObject (Swizzling)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = objc_getClass("UITabBarButton");
NSString *selectorString = @"initWithImage:selectedImage:label:withInsets:tabBar:";
Method originalMethod = class_getInstanceMethod(class, NSSelectorFromString(selectorString));
Method swizzledMethod = class_getInstanceMethod(class, NSSelectorFromString([@"swizzled_" stringByAppendingString:selectorString]));
method_exchangeImplementations(originalMethod, swizzledMethod);
});
}
- (id)swizzled_initWithImage:(id)image selectedImage:(id)selectedImage label:(id)label withInsets:(UIEdgeInsets)insets tabBar:(id)tabBar {
return [self swizzled_initWithImage:image selectedImage:selectedImage label:label withInsets:insets tabBar:tabBar];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment