In my application there are many UIViewControllers
with UINavigationControllers
. There must be a "back" button and a "home" UIButton
on the UINavigationBar
. All of this works fine.
But some of my UIViewControllers
have long names, and sometimes there is too small place left for it. I'm trying to replace the original label of the "back" button (it shows the title of the previous view) with a custom "Back", but whatever I tried it didn't work:
// Title didn't change
[self.navigationItem.backBarButtonItem setTitle:@"Back"];
// Action didn't set, no response from button ( button didn't do anything )
[self.navigationItem.leftBarButtonItem
setAction:self.navigationItem.backBarButtonItem.action];
And I need the "back" button to have a style like in this question: Draw custom Back button on iPhone Navigation Bar
More simply:
Try this
Target: customizing all back button on UINavigationBar to an white icon
Steps: 1. in "didFinishLaunchingWithOptions" method of AppDelete:
UIImage *backBtnIcon = [UIImage imageNamed:@"navBackBtn"];
2.in the "viewDidLoad" method of the common super ViewController class:
Try the following. It will definitely work:
Make sure you have an button image with the size of a navigation bar back button in your resource folder with name
back.png
.Feel free if any other assistance is required.
Suppose you have two controllers - Controller1 and Controller2. Controller2 is pushed from Controller1. So before pushing the Controller2 on the navigationController from Controller1
Now, in the viewDidLoad: method of Controller2, add the following snippet
and in the backButtonClicked method, you can perform the checks you want to.
If you're doing this all over the place like I am, you're better off implementing Anil's solution as a category: