如何自定义导航栏后退按钮

时间:2011-07-29 10:05:54

标签: iphone objective-c

当我执行导航时,将其添加的后退按钮保存到导航栏。

我们可以自定义后退按钮吗?

如果是,怎么做?

让我添加图片

@thanks提前。

3 个答案:

答案 0 :(得分:4)

您可以通过搜索堆栈溢出,谷歌或苹果文档轻松找到这一点,这几乎可以肯定是一个骗局,但无论如何:

UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"Custom" style:UIBarButtonItemStyleBordered target:self action:@selector(someSelector)];    
self.navigationItem.leftBarButtonItem = btn;
[btn release];

答案 1 :(得分:1)

You can hide back bar button and can create a custom button.  

  self.navigationItem.hidesBackButton=YES;
    UIButton *back = [[UIButton alloc] initWithFrame:CGRectMake(15, 7, 49, 29)];
    [back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *back1 = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = back1;

答案 2 :(得分:0)

制作IBoutlet并合成导航栏并连接nib的参考,并尝试使用以下代码。

- (void)viewDidLoad {
UIBarButtonItem * backButton = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backView)];
//navBar is your Navigation Bar
navBar.topItem.leftBarButtonItem = backButton;
}
-(IBAction) backView
{
    [self.navigationController popViewControllerAnimated:YES];
}