iOS 上UINavigationController视图压栈形式,可以在当前视图无限制push许多视图,然而一些会觉得自带的push按钮不够美观,而且当上的上一个页面title很长的时候,那个返回按钮就很长,怎样定义一个自己返回按钮呢?向第三幅图片一样。。。
需要push的视图里面定义一个事件
- (IBAction)pushVC:(id)sender { NavViewController *navVC = (NavViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"NavViewController"]; navVC.title = NSLocalizedString(@"设置", nil); [self.navigationController pushViewController:navVC animated:YES]; }
替换返回按钮,定义自定义按钮
- (void)viewDidLoad { [super viewDidLoad]; UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; backBtn.frame = CGRectMake(0, 0, 44, 44); [backBtn setImage:[UIImage p_w_picpathNamed:@"back.png"] forState:UIControlStateNormal]; [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn]; self.navigationItem.leftBarButtonItem = backItem; // Do any additional setup after loading the view. } -(void)doBack:(id)sender { [self.navigationController popViewControllerAnimated:YES]; }
×××地址:https://github.com/XFZLDXF/XFNavBarBtn
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。