Push 到指定的页面和拦截跳转并且一次性设置导航栏的item的文字的颜色

-(void)pushNextVCByInstance:(UIViewController *) nextVC{

    

    nextVC.hidesBottomBarWhenPushed =YES;

    UIBarButtonItem *item = [[UIBarButtonItemalloc]initWithTitle:@"返回"style:UIBarButtonItemStylePlaintarget:nilaction:nil];

    self.navigationItem.backBarButtonItem = item;

    [self.navigationControllerpushViewController:nextVCanimated:NO];

}

// 设置整个项目所有item的主题样式

+ (void)initialize

{

   

  /** 设置 UINavigationBar 上边的文字和颜色的属性 */

   UINavigationBar * navcBar = [UINavigationBarappearance];

   /**设置整个项目所有item的主题样式 */

    UIBarButtonItem *item = [UIBarButtonItemappearance];

    

    // 设置普通状态

    // keyNS****AttributeName

    NSMutableDictionary *textAttrs = [NSMutableDictionarydictionary];

    textAttrs[NSForegroundColorAttributeName] = [UIColororangeColor];

    textAttrs[NSFontAttributeName] = [UIFontsystemFontOfSize:15];

    [item setTitleTextAttributes:textAttrsforState:UIControlStateNormal];

    

    // 设置不可用状态

    NSMutableDictionary *disableTextAttrs = [NSMutableDictionarydictionary];

    disableTextAttrs[NSForegroundColorAttributeName] = [UIColorcolorWithRed:0.6green:0.6blue:0.6alpha:0.7];

    disableTextAttrs[NSFontAttributeName] = textAttrs[NSFontAttributeName];

    [item setTitleTextAttributes:disableTextAttrsforState:UIControlStateDisabled];

}

/**

 *  重写这个方法目的:能够拦截所有push进来的控制器

 *

 *  @param viewController即将push进来的控制器

 */

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

{

    if (self.viewControllers.count > 0) { // 这时push进来的控制器viewController,不是第一个子控制器(不是根控制器)

        /* 自动显示和隐藏tabbar */

        viewController.hidesBottomBarWhenPushed =YES;

        

        /* 设置导航栏上面的内容 */

        // 设置左边的返回按钮

        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItemitemWithTarget:selfaction:@selector(back)image:@"navigationbar_back"highImage:@"navigationbar_back_highlighted"];

        

        // 设置右边的更多按钮

        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItemitemWithTarget:selfaction:@selector(more)image:@"navigationbar_more"highImage:@"navigationbar_more_highlighted"];

    }


    [super pushViewController:viewControlleranimated:animated];

}


- (void)back

{

#warning 这里要用self,不是self.navigationController

    // 因为self本来就是一个导航控制器,self.navigationController这里是nil

    [selfpopViewControllerAnimated:YES];

}


- (void)more

{

    [selfpopToRootViewControllerAnimated:YES];

}



// 设置右边的按钮不可用状态

self.navigationItem.rightBarButtonItem.enabled =NO;


//修改特殊页面的导航栏按钮.....

- (void)viewDidLoad

{

    [superviewDidLoad];

    

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"设置"style:0target:selfaction:@selector(setting)];

}




你可能感兴趣的:(Push 到指定的页面和拦截跳转并且一次性设置导航栏的item的文字的颜色)