ios成长之路 Navigation的统一布局

来源:互联网 发布:正规的淘宝模特兼职 编辑:程序博客网 时间:2024/06/08 11:08

项目中都会有自己风格的返回键,重写方法可以不用每个页面都去写一次

// 统一设置标题颜色+(void)initialize{[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];}// 重写Navigation push方法-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{[super pushViewController:viewController animated:animated];if (self.viewControllers.count < 2) {    return;}else if (self.viewControllers.count == 2) {    // 设置非主页面navigation返回按钮    // 这点是我自己封装的 BackItemTools方法,也可以用系统的来设置    viewController.navigationItem.leftBarButtonItem = [BackItemTools itemWithTarget:self action:@selector(leftClick) image:@"nav_back" highlightedImage:@"nav_back"];    viewController.tabBarController.tabBar.hidden = YES;    _controller = viewController;}else{    viewController.navigationItem.leftBarButtonItem = [BackItemTools itemWithTarget:self action:@selector(leftClickOther) image:@"nav_back" highlightedImage:@"nav_back"];    viewController.tabBarController.tabBar.hidden = YES;    _controller = viewController;}  // 返回按钮实现方法}-(void)leftClick{[self popViewControllerAnimated:YES];_controller.tabBarController.tabBar.hidden = NO;}-(void)leftClickOther{[self popViewControllerAnimated:YES];}

以上内写在UINavigationController里边,然后把定义的这个UINavigationController作为父类也就是跟视图就可以了

原创粉丝点击