iOS 全局设置背景色方法
2018-12-28 本文已影响24人
longMountain
#import "UIViewController+AOP.h"
#import <objc/runtime.h>
@implementation UIViewController (AOP)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method originalMethod = class_getInstanceMethod(self, @selector(viewDidLoad));
Method swizzledMethod = class_getInstanceMethod(self, @selector(tj_viewDidLoad));
method_exchangeImplementations(originalMethod, swizzledMethod);
});
}
- (void)tj_viewDidLoad {
// 全局样式
[self tj_viewDidLoad];
// UIInputWindowController 会覆盖每一个控制器,避免为其设置颜色
Class class = NSClassFromString(@"UIInputWindowController");
if (self.class != class) {
self.view.backgroundColor = [UIColor lightGrayColor];
}
CLog(@"%@",self);
}
@end