123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // RDSNavController.m
- // LampRibbon
- //
- // Created by coderYK on 2017/8/7.
- // Copyright © 2017年 RD-iOS. All rights reserved.
- //
- #import "RDSNavController.h"
- #import "UIImage+Extension.h"
- #import "RDSRootControl.h"
- #import "RDSTabbarController.h"
- @interface RDSNavController ()
- @property (nonatomic, strong) UIBarButtonItem *backItem;
- @property (nonatomic, strong) UIBarButtonItem *space;
- @property (nonatomic, strong) UIImage *navFillImg; // ** <#注释#>*/
- @property (nonatomic, strong) UIImage *navCirImg; // ** <#注释#>*/
- @end
- @implementation RDSNavController
- - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
-
- if (self.childViewControllers.count > 0) {
-
-
-
- viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
- //viewController.navigationItem.leftBarButtonItems = @[self.space, self.backItem];
- viewController.navigationItem.leftBarButtonItems = @[self.backItem];
-
- if ([viewController isKindOfClass:[RDSTabbarController class]]) {
- if (self.childViewControllers.count < 2) {
- viewController.navigationItem.leftBarButtonItems = nil;
- viewController.navigationItem.hidesBackButton = YES;
- }
- }
- }
-
- [super pushViewController:viewController animated:animated];
- }
- - (void)p_popViewController {
-
- [self popViewControllerAnimated:YES];
- }
- - (UIBarButtonItem *)backItem {
-
- if (_backItem == nil) {
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
- backBtn.frame = CGRectMake(0, 0, 30, 30);
- [backBtn addTarget:self action:@selector(p_popViewController) forControlEvents:UIControlEventTouchUpInside];
- _backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
- }
- return _backItem;
- }
- - (UIBarButtonItem *)space {
-
- if (_space == nil) {
- _space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
- target:nil action:nil];
- _space.width = -15;
- }
- return _space;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // 设置导航栏背景图片
- // [self.navigationBar setBackgroundImage:[UIImage rds_imageWithColor:RDSNavBarColor] forBarMetrics:UIBarMetricsDefault];
- //
- // // 去掉导航栏下边的黑边
- // [self.navigationBar setShadowImage:[UIImage new]];
- //
- // // 设置标题字体、颜色
- // UIFont *font = [UIFont rds_titiFontStyle:FontStyle_SemiBold size:22];
- // [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:font}];
- //
-
-
- [self navBarColor:RDSNavBarColor];
- // [self updateNavigationBarColor:RDSNavBarColor];
-
- // [self p_setupNavBar];
-
- }
- - (void)navBarColor:(UIColor *)color{
- //navigation标题文字颜色
- NSDictionary *dic = @{NSForegroundColorAttributeName:RGB(39, 46, 59),
- NSFontAttributeName:[UIFont boldSystemFontOfSize:18]};
- if (@available(iOS 15.0, *)) {
- UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];
- // [barApp configureWithOpaqueBackground];
- barApp.backgroundColor = color;
- barApp.shadowColor = UIColor.clearColor;
- barApp.titleTextAttributes = dic;
- self.navigationBar.scrollEdgeAppearance = barApp;
- self.navigationBar.standardAppearance = barApp;
- }else{
- //背景色
- self.navigationBar.barTintColor = color;
- self.navigationBar.titleTextAttributes = dic;
- [self.navigationBar setShadowImage:[UIImage new]];
- [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
- }
- //不透明
- self.navigationBar.translucent = NO;
- //navigation控件颜色
- self.navigationBar.tintColor = [UIColor whiteColor];
- }
- - (void)updateNavigationBarColor:(UIColor *)color {
- UINavigationBar *bar = self.navigationBar;// 重置背景和阴影颜色
- if (@available(iOS 13.0, *)) {
- UINavigationBarAppearance *barAppearance = [UINavigationBarAppearance new];
- [barAppearance configureWithOpaqueBackground];
- barAppearance.backgroundColor = color; // 设置背景颜色
- barAppearance.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:24]}; // 设置导航栏字体颜色和大小
- barAppearance.shadowColor = [UIColor clearColor]; // 设置导航栏底部的分割线不显示
-
- bar.scrollEdgeAppearance = bar.standardAppearance = barAppearance;
- [bar setShadowImage:[UIImage new]];
- } else {
- // Fallback on earlier versions
- }
- [bar setBackgroundImage:[UIImage rds_imageWithColor:color] forBarMetrics:UIBarMetricsDefault];
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- UIViewController *topVC = self.topViewController;
- return [topVC preferredStatusBarStyle];
- }
- -(void) p_setupNavBar{
-
- UIImage *cirImg = [UIImage imageNamed:@"nav_mine_top"];
- // 四个数值对应图片中距离上、左、下、右边界的不拉伸部分的范围宽度
- cirImg = [cirImg resizableImageWithCapInsets:UIEdgeInsetsMake(40, 40, 40, 40) resizingMode:UIImageResizingModeStretch];
- self.navCirImg = cirImg;
-
- UIImage *fillImg = [UIImage imageNamed:@"nav_top_fill"];
- // 四个数值对应图片中距离上、左、下、右边界的不拉伸部分的范围宽度
- fillImg = [fillImg resizableImageWithCapInsets:UIEdgeInsetsMake(40, 40, 40, 40) resizingMode:UIImageResizingModeStretch];
- self.navFillImg = fillImg;
-
- [self.navigationBar setBackgroundImage:cirImg forBarMetrics:UIBarMetricsDefault];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|