简体   繁体   中英

How to Customize the navigation bar back button

When i do navigation default its added back button to navigation bar.

Do we can customize the back button?

If yes How to do that?

Let me add the pictures

@thanks in advance.

You could have found this very easily by searching stack overflow, google, or apple docs and this is almost certainly a dupe but anyhow:

UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"Custom" style:UIBarButtonItemStyleBordered target:self action:@selector(someSelector)];    
self.navigationItem.leftBarButtonItem = btn;
[btn release];
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;

Make IBoutlet and synthesize of your navigation bar and also connect reference from nib, and try following code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM