自定义全局导航的样式

@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];
    }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言: 就在上个月也就是年末的时候,打开了以前的一个项目,忽然发现导航栏返回按钮几乎看不到了,一直忙另外一个项目,...
    独孤红雨阅读 16,791评论 4 17
  • 1,创建并使用一个UINavigationController UINavigationController *a...
    指尖的跳动阅读 550评论 0 0
  • 1.自定义控件 a.继承某个控件 b.重写initWithFrame方法可以设置一些它的属性 c.在layouts...
    圍繞的城阅读 3,538评论 2 4
  • 一夜冬雨,湿漉漉的银杏树下黄叶堆积。抬眼看,昨天如千层金箔的树冠已成了光秃秃的枝桠,颤颤惊惊裸举于沥沥细雨,有几分...
    灵山阅读 794评论 0 2
  • After reading the speech,i study many ability and realiz...
    339张瑞阅读 256评论 1 0