RALoginNavigationController.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // RALoginNavigationController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/10/13.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RALoginNavigationController.h"
  9. @interface RALoginNavigationController ()
  10. {
  11. CAGradientLayer *_gradientLayer;
  12. UIView *_barBackgroundView, *_gradientView;
  13. }
  14. @end
  15. @implementation RALoginNavigationController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. [self _configAppearance];
  20. }
  21. -(void) viewDidAppear:(BOOL)animated
  22. {
  23. [super viewDidAppear:animated];
  24. if(_gradientView!=nil)
  25. return;
  26. _gradientLayer = [CAGradientLayer layer];
  27. UIColor *orangeWhiteColor = ApexDriverOrangeWhiteColor;
  28. UIColor *orangeColor = ApexDriverOrangeColor;
  29. _gradientLayer.colors = @[(__bridge id)orangeColor.CGColor, (__bridge id)orangeWhiteColor.CGColor];
  30. _gradientLayer.startPoint = CGPointMake(0, 0);
  31. _gradientLayer.endPoint = CGPointMake(1, 0);
  32. _barBackgroundView = [self.navigationBar.subviews objectAtIndex:0];
  33. _gradientView = [UIView new];
  34. _gradientView.frame = _barBackgroundView.bounds;
  35. _gradientLayer.frame = _gradientView.bounds;
  36. [_gradientView.layer addSublayer:_gradientLayer];
  37. [_barBackgroundView addSubview:_gradientView];
  38. [_barBackgroundView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:(__bridge void * _Nullable)(self)];
  39. }
  40. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  41. if (context == (__bridge void * _Nullable)(self)) {
  42. _gradientView.frame = _barBackgroundView.bounds;
  43. _gradientLayer.frame = _gradientView.bounds;
  44. }
  45. }
  46. - (void)dealloc {
  47. [[NSNotificationCenter defaultCenter] removeObserver:self];
  48. [_barBackgroundView removeObserver:self forKeyPath:@"frame"];
  49. }
  50. - (UIStatusBarStyle)preferredStatusBarStyle {
  51. return UIStatusBarStyleLightContent;
  52. }
  53. - (void)_configAppearance {
  54. [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ApexDriverWhiteColor}]; // Title Color
  55. [self.navigationBar setTintColor:ApexDriverWhiteColor]; // BarItem颜色
  56. self.navigationBar.barTintColor = ApexDriverOrangeColor; // 背景色
  57. self.navigationBar.translucent = NO;
  58. // 去除Bar黑色分割线
  59. self.navigationBar.shadowImage = [UIImage new];
  60. [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  61. }
  62. @end