Setting up reused navigation bar item button for left button

I am using a Navigation Bar through out my application although not controller via a Navigation Controller (added to the VCs via Storyboard).

I would like to set a left bar button item to be the same on the navigation controller through out its use. This is a stack style for the menu which will slide in:

What is the correct way to implement this button following standard practice? I can strip the bg of the button to be repeatable which is not an issue, but how do I complete the following: 1. Implement an image within the button 2. Implement this button through appearance API if possible so the code is not glue code and re-used on all VCs that have this.

If I cannot do via appearance, what would be the best approach to not have to include this code over and over again in the controllers that use this?

Further to this, is there a way to show this button item in a storyboard and be linked in the storyboard/have a use other than visually.

Answers


Ah ok, now I'm following you. In that case just create a custom navBar class and either add that to your pch then use it where necessary or create a custom UIViewController subclass called "UIViewControllerWithNavBar" then you can use that class as a replacement for the default UIViewController class.

@interface SomeViewController : UIViewControllerWithNavBar

This will allow you to reuse the class throughout your app with the navBar already added.


I recently wrote a blog post about this issue, but for the rightBarButtonItem. I'm not sure if the "back" functionality will require tweaks, but here's the blog post if interested: http://www.codebestowed.com/ios-shared-barbuttonitems/

The basic idea is to subclass UINavigationController, give it a BarButtonItem property (self.myButton in the code below) and add code similar to:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;
}

- (void)navigationController:(UINavigationController *)navigationController
    willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (!viewController.navigationItem.rightBarButtonItem) {
        viewController.navigationItem.rightBarButtonItem = self.myButton;
    }
}

The blog post details how you can set this up further in InterfaceBuilder, which requires a bit of a hack (too much to go into in this answer).


Need Your Help

How to crop an image on the right to match the width of a containing element?

html css image crop

I searched the internet, but couldn't find the exact solution.