欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

iOS 全局设置背景色方法

程序员文章站 2022-07-13 12:58:03
...
#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

转载于:https://www.jianshu.com/p/b938283f30c1