1.采用系统自带的返回按钮。经常要隐藏title
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
if (self.childViewControllers.count >= 1) {
//藏BottomBar
viewController.hidesBottomBarWhenPushed = YES;
}
//跳转
[super pushViewController:viewController animated:animated];
}
以下是网络搜索到的方法
1.这种方法会被系统给拉伸,需要在当前控制器里面设置,不改变系统手势滑动返回
UIImage *backButtonImage = [[UIImage imageNamed:@"back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
2.这种方法在父类方法中设置,不改变系统手势滑动返回
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];backItem.title = @"返回";
self.navigationItem.backBarButtonItem = backItem;//主要是以下两个图片设置self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:@"backPic"];
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"backPic"];
3.这种方法会失去手势滑动返回的功能
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[backButton setImage:[UIImage imageNamed:@"left_select_img.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backItemClick) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];;//覆盖返回按键
网友评论