SPSBNavigationController.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // SPSBNavigationController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/19.
  6. //
  7. #import "SPSBNavigationController.h"
  8. #import "SPSBColorProfile.h"
  9. #import "SPSBGeneralManager.h"
  10. #import <JXHGeneralTools.h>
  11. #import <JXHMacro.h>
  12. @interface SPSBNavigationController ()
  13. @end
  14. @implementation SPSBNavigationController
  15. - (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
  16. self = [super initWithRootViewController:rootViewController];
  17. if (!self) return nil;
  18. self.modalPresentationStyle = UIModalPresentationFullScreen;
  19. return self;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. if (@available(iOS 15.0, *)) {
  24. UINavigationBarAppearance *navigationBarAppearance = [UINavigationBarAppearance new];
  25. // 去掉半透明效果
  26. navigationBarAppearance.backgroundEffect = nil;
  27. // 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
  28. navigationBarAppearance.shadowColor = [UIColor clearColor];
  29. navigationBarAppearance.backgroundColor = spsb_FFFFFF_color(1.f);
  30. NSDictionary *attributes = @{NSForegroundColorAttributeName: spsb_333333_color(), NSFontAttributeName: spsb_mediumFont(16)};
  31. navigationBarAppearance.titleTextAttributes = attributes;
  32. self.navigationBar.scrollEdgeAppearance =
  33. self.navigationBar.standardAppearance = navigationBarAppearance;
  34. } else {
  35. [self setBarBackgroundColor:spsb_FFFFFF_color(1.f)];
  36. [self setBarTitleColor:spsb_333333_color()];
  37. }
  38. }
  39. - (void)setBarTitleColor:(UIColor *)color {
  40. NSDictionary *attributes = @{NSForegroundColorAttributeName: color, NSFontAttributeName: spsb_mediumFont(16)};
  41. if (@available(iOS 15.0, *)) {
  42. UINavigationBarAppearance *navigationBarAppearance = [[UINavigationBarAppearance alloc] initWithBarAppearance:self.navigationBar.standardAppearance];
  43. navigationBarAppearance.titleTextAttributes = attributes;
  44. self.navigationBar.scrollEdgeAppearance =
  45. self.navigationBar.standardAppearance = navigationBarAppearance;
  46. } else {
  47. [self.navigationBar setTitleTextAttributes:attributes];
  48. }
  49. }
  50. - (void)setBarBackgroundColor:(UIColor *)color {
  51. if (@available(iOS 15.0, *)) {
  52. UINavigationBarAppearance *navigationBarAppearance = [[UINavigationBarAppearance alloc] initWithBarAppearance:self.navigationBar.standardAppearance];
  53. navigationBarAppearance.backgroundColor = color;
  54. self.navigationBar.scrollEdgeAppearance =
  55. self.navigationBar.standardAppearance = navigationBarAppearance;
  56. } else {
  57. [self.navigationBar setBackgroundImage:jxh_createImage(color, CGSizeMake(100, 100)) forBarMetrics:UIBarMetricsDefault];
  58. [self.navigationBar setShadowImage:jxh_getImage(navigation_line)];
  59. }
  60. }
  61. - (UIStatusBarStyle)preferredStatusBarStyle {
  62. return UIStatusBarStyleDefault;
  63. }
  64. - (BOOL)shouldAutorotate {
  65. return false;
  66. }
  67. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  68. return UIInterfaceOrientationMaskPortrait;
  69. }
  70. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  71. return UIInterfaceOrientationPortrait;
  72. }
  73. - (UIViewController *)childViewControllerForStatusBarStyle {
  74. return self.topViewController;
  75. }
  76. @end