Rafael Nascimento
Rafael Nascimento

Reputation: 309

Setting a custom navigation item backBarButtonItem icon [Objective-c]

I'm trying to set a custom navigation item backBarButtonItem icon. So far I'm using this code on the preveous view controller's view did load:

- (void)viewDidLoad{
[super viewDidLoad];


UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back-arrow"] style:UIBarButtonItemStylePlain target:nil
                                                                action:nil];
self.navigationItem.backBarButtonItem = myBackButton;}

And here is the result:

enter image description here

I have two icons and I can't figure out what is going on. I want to get rid of the native one and keep mine.

Can someone help me?

UPDATE:

Using:

[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back-arrow"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back-arrow"]];

The result is:

It solves the initial problem, but I got a icon that is too big. How can I resize it? I'm using an icon that is 53x46px.

Upvotes: 2

Views: 1092

Answers (1)

Ookey
Ookey

Reputation: 652

Try this code:

[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"your-image"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"your-image"]];

Upvotes: 3

Related Questions