// // RALoginNavigationController.m // Apex And Drivers // // Created by Jack on 2018/10/13. // Copyright © 2018年 USAI. All rights reserved. // #import "RALoginNavigationController.h" @interface RALoginNavigationController () { CAGradientLayer *_gradientLayer; UIView *_barBackgroundView, *_gradientView; } @end @implementation RALoginNavigationController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self _configAppearance]; } -(void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if(_gradientView!=nil) return; _gradientLayer = [CAGradientLayer layer]; UIColor *orangeWhiteColor = ApexDriverOrangeWhiteColor; UIColor *orangeColor = ApexDriverOrangeColor; _gradientLayer.colors = @[(__bridge id)orangeColor.CGColor, (__bridge id)orangeWhiteColor.CGColor]; _gradientLayer.startPoint = CGPointMake(0, 0); _gradientLayer.endPoint = CGPointMake(1, 0); _barBackgroundView = [self.navigationBar.subviews objectAtIndex:0]; _gradientView = [UIView new]; _gradientView.frame = _barBackgroundView.bounds; _gradientLayer.frame = _gradientView.bounds; [_gradientView.layer addSublayer:_gradientLayer]; [_barBackgroundView addSubview:_gradientView]; [_barBackgroundView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:(__bridge void * _Nullable)(self)]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (context == (__bridge void * _Nullable)(self)) { _gradientView.frame = _barBackgroundView.bounds; _gradientLayer.frame = _gradientView.bounds; } } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [_barBackgroundView removeObserver:self forKeyPath:@"frame"]; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } - (void)_configAppearance { [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ApexDriverWhiteColor}]; // Title Color [self.navigationBar setTintColor:ApexDriverWhiteColor]; // BarItem颜色 self.navigationBar.barTintColor = ApexDriverOrangeColor; // 背景色 self.navigationBar.translucent = NO; // 去除Bar黑色分割线 self.navigationBar.shadowImage = [UIImage new]; [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; } @end