Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set all back buttons like leftBarButtonItem with custom image

How do I set a custom image to all back buttons of view controllers pushed in a UINavigationController?

My issues are:

  • must look like leftBarButtonItem, position-wise (because the backBarButtonItem itself is too glued to the left and I can't seem to change it's horizontal alignment).
  • has to be on all back actions (instead of manually setting on each view controller).
  • having a method setCustomBackButton and calling it on each view controller is also not an option, I'm looking for something like UINavigationBar.appearance(), i.e., throughout the app.

Something like this: enter image description here But with the back action working without me manually setting the selector on each view controller.

UPDATE: In response to Joe's solution, I'm getting that error: enter image description here

like image 662
Rodrigo Ruiz Avatar asked Nov 30 '25 11:11

Rodrigo Ruiz


1 Answers

UINavigationBar.appearance().backIndicatorImage = UIImage(named: "backArrow")

See Here: https://www.raywenderlich.com/108766/uiappearance-tutorial

like image 186
crizzis Avatar answered Dec 03 '25 02:12

crizzis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!