美文网首页
自定义全局导航的样式

自定义全局导航的样式

作者: Hamiltonian | 来源:发表于2018-05-23 10:37 被阅读22次

    @interface EYNavigationController ()

    @end

    @implementation EYNavigationController

    • (void)initialize
      {
      if (self == [EYNavigationController class]) {

        //隐藏导航栏分割线
        [[UINavigationBar appearance] setShadowImage:[UIImage new]];
        //设置导航栏背景颜色
        [UINavigationBar appearance].barTintColor=kNavBackColor;
        //设置导航栏标题 大小 颜色
        NSDictionary * navigationTitleAttDic = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:UIColorFromRGB(74,74,74)};
        [[UINavigationBar appearance] setTitleTextAttributes:navigationTitleAttDic];
      

      }
      }

    • (void)viewDidLoad {
      [super viewDidLoad];

      self.navigationBar.translucent=NO;

    }

    • (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
      {
      if (self.viewControllers.count > 0) { // 此时push进来的viewController是第二个子控制器
      // 自动隐藏tabbar
      viewController.hidesBottomBarWhenPushed = YES;

        if (viewController.navigationItem.leftBarButtonItem == nil) {
            
            UIImage * backImage =[[UIImage imageNamed:@"ic_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            viewController.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(popself)];
        }
      

      }
      // 调用父类pushViewController,self.viewControllers数组添加对象viewController
      [super pushViewController:viewController animated:animated];
      }

    • (void)popself
      {
      // 这里要用self,不能用self.navigationViewController,因为self本身就是导航控制器对象,self.navigationViewController是nil
      [self popViewControllerAnimated:YES];
      }

    相关文章

      网友评论

          本文标题:自定义全局导航的样式

          本文链接:https://www.haomeiwen.com/subject/hdzljftx.html