第一次這么大規(guī)模的使用runtime , 原來(lái)只知道runtime, 但是感覺(jué)離我的生活好遠(yuǎn), 偶爾使用還是改輸入框的光標(biāo)的顏色 ????. 這次時(shí)間緊, 任務(wù)重, 為了節(jié)省時(shí)間, 就打上了runtime的主意
沒(méi)想到這么好用
果然人都是被逼出來(lái)的
#import "UIViewController+LoadVC.h"
#import <objc/runtime.h>
@implementation UIViewController (LoadVC)
+(void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method oldMethod = class_getInstanceMethod([self class], @selector(viewWillAppear:));
Method newMethod = class_getInstanceMethod([self class], @selector(hook_ViewWillAppear:));
method_exchangeImplementations(oldMethod, newMethod);
});
}
-(void)hook_ViewWillAppear:(BOOL)appear{
NSString *className = NSStringFromClass([self class]);
NSLog(@"%@ will appear", className);
[self hook_ViewWillAppear:appear];
}
@end