如何从后退按钮隐藏导航栏标题“BACK”

时间:2017-04-27 12:11:38

标签: ios objective-c navigationbar

我的疑问是如何从后退按钮隐藏导航栏标题“BACK”(但需要显示后退箭头。)

谢谢。

2 个答案:

答案 0 :(得分:1)

使用此:

YourViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewController"];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationController pushViewController:viewController animated:YES];

答案 1 :(得分:0)

我建议你使用如下代码:

- (void)configureNavigationBarButtonItem
{

UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
[cancel setFrame:CGRectMake(0, 0, 50, 50)];

[cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cancel.titleLabel setFont:[UIFont fontWithName:@"Verdana" size:13.0f]];
cancel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
[cancel addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
cancel.tag=3200;

imgBack = [[UIImageView alloc]initWithFrame:CGRectMake(5, 15, 18, 18)];
imgBack.image = [UIImage imageNamed:@"back_black"];
[cancel addSubview:imgBack];


UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithCustomView:cancel];
self.navigationItem.leftBarButtonItem = cancelBtn;

}
- (void)goBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}