Robert Saunders
Robert Saunders

Reputation: 403

How to change UINavigation Back Button to an image?

So I have these images that are used for a custom Nav bar and items, they look like this.Currently I have the custom nav bar set up, however I don't know how change the default "back" button to the back button image below, this is what I want to know? Any help would be greatly appreciated. Note: I am using storyboards. Thanks

This is the nav bar:

enter image description here

This is my back button that i don't know how to imlpement.

enter image description here

Upvotes: 2

Views: 9845

Answers (2)

SBotirov
SBotirov

Reputation: 14158

If you want add back button to UINavigation try this:

First create back button:

1. If you don`t need to back action:

        UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
        style:UIBarButtonItemStyleDone target:nil action:nil];

2. If you want to create back button with image then try this:

    UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
    imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:nil
    action:nil]

3. If you want to create back button with image and action then try this:

    UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
    imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:self
    action:@selector(goBack:)]

    - (void)goBack:(id)sender {
        [self.navigationController popViewControllerAnimated:YES];
    }

After created back button add it to NavigationBar:

self.navigationItem.backBarButtonItem = myBackButton;

Implementation of logic "Add back button" you can put in viewDidLoad method:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.backBarButtonItem = myBackButton;
}

And you need to more information see this: UIBarButtonItem Class Reference

Here more examples for you:


Upvotes: 10

art-divin
art-divin

Reputation: 1645

Here is how you can do this:

UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:target action:action;]
self.navigationItem.rightButtonItem = back;

For more info about UIBarButtonItem, go here.

Also try to search next time for similar questions before posting new.

Upvotes: 0

Related Questions