In a storyboard, I create a navigation bar by using "Embed in".
I'm trying to replace the original image of back button, which is like this
by my back button image, which is
How to do this?
In a storyboard, I create a navigation bar by using "Embed in".
I'm trying to replace the original image of back button, which is like this
by my back button image, which is
How to do this?
In your controllers viewDidLoad method add following code..
UIImage *leftbuttonImage = [UIImage imageNamed:@"yourimagename"];
UIButton *leftbutton = [UIButton buttonWithType:UIButtonTypeCustom];
[leftbutton setImage:leftbuttonImage forState:UIControlStateNormal];
leftbutton.frame = CGRectMake(0, 0, 35, 35);
[leftbutton addTarget:self action:@selector(showLeftMenuPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarleftItem = [[UIBarButtonItem alloc] initWithCustomView:leftbutton];
self.navigationItem.leftBarButtonItem = customBarleftItem;
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backBtnImage = [UIImage imageNamed:@"BackBtn.png"] ;
[backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
backBtn.frame = CGRectMake(0, 0, 54, 30);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
self.navigationItem.leftBarButtonItem = backButton;
and declare goback:
- (void)goback
{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)setUpNAvigationBackBarButton
{
UIImage* image3 = [UIImage imageNamed:@"icon_back.png"];
CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton addTarget:self action:@selector(YourMethod which you wanna call on back button
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
[self.navigationItem setLeftBarButtonItem:mailbutton animated:YES];
}
just call this function in your viewdidLoad. I have used same this function in ma code. working fine.. you can use it.
Swift version :-
self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "HomeLeft@2x")
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "HomeLeft@2x")
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
put this on viewDidLoad( )