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



我的疑问是如何隐藏backbutton的导航栏标题" Back"(但需要显示Backbutton Arrow。(

谢谢。

使用以下:

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

我建议您使用以下代码:

- (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];
}

最新更新