// // SPSBNavigationController.m // 我的社保 // // Created by shanp on 2021/4/19. // #import "SPSBNavigationController.h" #import "SPSBColorProfile.h" #import "SPSBGeneralManager.h" #import #import @interface SPSBNavigationController () @end @implementation SPSBNavigationController - (instancetype)initWithRootViewController:(UIViewController *)rootViewController { self = [super initWithRootViewController:rootViewController]; if (!self) return nil; self.modalPresentationStyle = UIModalPresentationFullScreen; return self; } - (void)viewDidLoad { [super viewDidLoad]; if (@available(iOS 15.0, *)) { UINavigationBarAppearance *navigationBarAppearance = [UINavigationBarAppearance new]; // 去掉半透明效果 navigationBarAppearance.backgroundEffect = nil; // 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线) navigationBarAppearance.shadowColor = [UIColor clearColor]; navigationBarAppearance.backgroundColor = spsb_FFFFFF_color(1.f); NSDictionary *attributes = @{NSForegroundColorAttributeName: spsb_333333_color(), NSFontAttributeName: spsb_mediumFont(16)}; navigationBarAppearance.titleTextAttributes = attributes; self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance = navigationBarAppearance; } else { [self setBarBackgroundColor:spsb_FFFFFF_color(1.f)]; [self setBarTitleColor:spsb_333333_color()]; } } - (void)setBarTitleColor:(UIColor *)color { NSDictionary *attributes = @{NSForegroundColorAttributeName: color, NSFontAttributeName: spsb_mediumFont(16)}; if (@available(iOS 15.0, *)) { UINavigationBarAppearance *navigationBarAppearance = [[UINavigationBarAppearance alloc] initWithBarAppearance:self.navigationBar.standardAppearance]; navigationBarAppearance.titleTextAttributes = attributes; self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance = navigationBarAppearance; } else { [self.navigationBar setTitleTextAttributes:attributes]; } } - (void)setBarBackgroundColor:(UIColor *)color { if (@available(iOS 15.0, *)) { UINavigationBarAppearance *navigationBarAppearance = [[UINavigationBarAppearance alloc] initWithBarAppearance:self.navigationBar.standardAppearance]; navigationBarAppearance.backgroundColor = color; self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance = navigationBarAppearance; } else { [self.navigationBar setBackgroundImage:jxh_createImage(color, CGSizeMake(100, 100)) forBarMetrics:UIBarMetricsDefault]; [self.navigationBar setShadowImage:jxh_getImage(navigation_line)]; } } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; } - (BOOL)shouldAutorotate { return false; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } - (UIViewController *)childViewControllerForStatusBarStyle { return self.topViewController; } @end