Reputation: 1681
Any idea why the custom nav bar back button image isn't displaying with this code?
instead of showing the uiimage it's showing the "< Back" default iOS button in text only
[self.navigationController setNavigationBarHidden:NO animated:NO];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"freccia.png"] landscapeImagePhone:nil style:UIBarButtonItemStylePlain target:nil action:@selector(backBtnPress)];
could it be this parameter? UIBarButtonItemStylePlain
thanks
Upvotes: 0
Views: 100
Reputation: 6079
use this code:
UIImage *imageBack = [UIImage imageNamed:@"yourImage.png"];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
btnBack.bounds = CGRectMake(0, 0, imageBack.size.width, imageBack.size.height);
[btnBack setBackgroundImage:imageBack forState:UIControlStateNormal];
[btnBack addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonBack = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = barButtonBack;
-(void)back {
[self.navigationController popViewControllerAnimated:YES];
}
Upvotes: 2
Reputation: 1269
you can solve this problem by two ways 1. use leftBarButtonItem instead of backBarButtonItem 2. try the below code
self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
Upvotes: 0
Reputation: 4566
You usually set the back button in the parent view controller. However, it might just be easier to use leftBarButtonItem
instead of backBarButtonItem
.
Upvotes: 1