更改UINavigationController中NavigationBar返回按钮的标题

UINavigationController中返回按钮默认的标题是Return/返回,要更改返回按钮的标题,必须在push视图控制器之间加上以下的代码:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" styleUIBarButtonItemStuleBorderd target:nil action nil];
[self.navigationItem setBackBarButtonItem:backButton];
[backButton release];
这样navigationBar上返回按钮的标题就变成了Back,点击按钮时默认会返回上一级视图。除了这种方法,还可以自己定义一个按钮来更改返回按钮,不过这个方法需要自己定义按钮的点击事件:

UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
back.titleLabel.font = [UIFont boldSystemFontOfSize:13];
[back setTitle:@"Back" forState:UIControlStateNormal];
[back setFrame:CGRectMake(5, 2, 52, 30)];
[back setBackgroundImage:[UIImage imageNamed:@"bar_return"] forState:UIControlStateNormal];
[back addTarget:self action:@selector(popDiyView) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.leftBarButtonItem = barButton;
这个方法需要自己增加一个popDiyView方法来pop当前的视图





你可能感兴趣的:(change,title,of,retu)