I want to set the back button in my UINavigationBar to this image:
I don't want the image to be embedded in the standard back button image, I just want this image to appear.
I know from looking at other questions that I can use:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
to set the background image of the back button. But this causes the image to be stretched, and this particular image is not, as far as I can tell, suitable to be stretched.
Is there a way that I can replace back button image with my image?
I am supporting iOS 5.0 and up.
Since iOS 7+ you should use backIndicatorImage
property of UINavigationBar
to set your custom indicator image. Also you need to provide backIndicatorTransitionMaskImage
(you may use the same image for both).
Swift:
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "back-button-image")
UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "back-button-image")
Objective-C:
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back-button-image"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back-button-image"]];