BGNavigationController.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // BGNavigationController.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 2017/6/26.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGNavigationController.h"
  9. @interface BGNavigationController ()
  10. @end
  11. @implementation BGNavigationController
  12. - (instancetype)initWithRootViewController:(UIViewController *)rootViewController
  13. {
  14. if (self = [super initWithRootViewController:rootViewController])
  15. {
  16. self.edgesForExtendedLayout = UIRectEdgeNone;
  17. self.extendedLayoutIncludesOpaqueBars = NO;
  18. self.view.backgroundColor = kWhiteColor;
  19. }
  20. return self;
  21. }
  22. - (void)viewDidLoad
  23. {
  24. [super viewDidLoad];
  25. [self setNavigationBarAppearance];
  26. }
  27. - (void)setNavigationBarAppearance
  28. {
  29. [[UINavigationBar appearance] setBackgroundImage:[BGUtils imageWithColor:kNavBarThemeColor] forBarMetrics:UIBarMetricsDefault];
  30. NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
  31. textAttrs[NSForegroundColorAttributeName] = kAppGrayColor1; // 设置item颜色
  32. textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:16]; // 统一设置item字体大小
  33. [UINavigationBar appearance].titleTextAttributes=textAttrs;
  34. if (@available(iOS 13.0, *)) {
  35. UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
  36. appearance.shadowImage = [UIImage imageWithColor:kWhiteColor];
  37. [appearance configureWithOpaqueBackground];
  38. appearance.backgroundColor = kWhiteColor;
  39. self.navigationBar.standardAppearance = appearance;
  40. self.navigationBar.scrollEdgeAppearance = appearance;
  41. [self.navigationBar setShadowImage:nil];
  42. [self.navigationBar setShadowImage:[UIImage imageWithColor:kWhiteColor]];
  43. [self.navigationBar setBackgroundImage: [UIImage imageWithColor:kWhiteColor] forBarMetrics:UIBarMetricsDefault];
  44. } else {
  45. // Fallback on earlier versions
  46. }
  47. // if (@available(iOS 13.0, *)) {
  48. //
  49. // UINavigationBarAppearance *barApp = [[UINavigationBarAppearance alloc] init];
  50. // [barApp configureWithOpaqueBackground];
  51. // barApp.titleTextAttributes = textAttrs;
  52. // barApp.backgroundColor = kNavBarThemeColor;
  53. // self.navigationBar.standardAppearance = barApp;
  54. // self.navigationBar.scrollEdgeAppearance = barApp;
  55. // }
  56. }
  57. - (UIStatusBarStyle)preferredStatusBarStyle {
  58. UIViewController *topVC = self.topViewController;
  59. return [topVC preferredStatusBarStyle];
  60. }
  61. @end