美文网首页
iOS 全局设置背景色方法

iOS 全局设置背景色方法

作者: longMountain | 来源:发表于2018-12-28 15:49 被阅读24次
#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

相关文章

网友评论

      本文标题:iOS 全局设置背景色方法

      本文链接:https://www.haomeiwen.com/subject/jaxelqtx.html