全局设置页面颜色 返回按钮样式 iOS

思路

1.建个UIViewController的分类

2.hook方法viewDidLoad(Aspects是三方库 可以不用)

3.看下面蓝色部分代码

 

#import "UIViewController+TJSwizzling.h"

#import <Aspects.h>

@implementation UIViewController (TJSwizzling)

 

+ (void)load{

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        [self aspect_hookSelector:@selector(viewDidLoad) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> aspectInfo) {

            [[aspectInfo instance] swizzling_viewDidLoad];

        } error:NULL];

    });

}

 

#pragma mark - ViewDidLoad

- (void)swizzling_viewDidLoad{

 

    //全局设置页面为白色

    //  UIInputWindowController 会覆盖每一个控制器,避免为其设置颜色

    Class class = NSClassFromString(@"UIInputWindowController");

    if (self.class != class) {

        self.view.backgroundColor = [UIColor whiteColor];

    }

    //全局设置返回按钮样式

    if (self.navigationController && [self isEqual:self.navigationController.topViewController]) {

        UIImage *buttonNormal = [[UIImage imageNamed:@"VideoBar_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        [self.navigationController.navigationBar setBackIndicatorImage:buttonNormal];

        [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:buttonNormal];

        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

        self.navigationItem.backBarButtonItem = backItem;

    }

}

 

@end

全局设置页面颜色 返回按钮样式 iOS

上一篇:vue中axios使用一:axios做拦截器


下一篇:Spring源码解析之ConfigurableApplicationContext