how to add an image as a back button to the left side of the navigation bar. I need a left arrow in the navigation bar. I need a solution in swift 4.
Asked
Active
Viewed 320 times
-2
-
6Possible duplicate of [UIBarButtonItem in navigation bar programmatically?](https://stackoverflow.com/questions/30022780/uibarbuttonitem-in-navigation-bar-programmatically) – dahiya_boy Jul 08 '19 at 09:46
-
3Possible duplicate of [Custom image for UINavigation Back Button in iOS 7](https://stackoverflow.com/questions/18912638/custom-image-for-uinavigation-back-button-in-ios-7) – RajeshKumar R Jul 08 '19 at 09:50
-
check my answer here https://stackoverflow.com/questions/56857833/adjust-position-of-custom-navigation-back-button/56859328#56859328 – m1sh0 Jul 08 '19 at 10:59
3 Answers
0
You can do something like that:
let yourBackImage = UIImage(named: "back_button_image")
self.navigationController?.navigationBar.backIndicatorImage = yourBackImage
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = yourBackImage
self.navigationController?.navigationBar.backItem?.title = "Custom"

Paolo Mossini
- 1,064
- 2
- 15
- 23
0
let backButtonItem = UIBarButtonItem(image: UIImage(named: "left_arrow_icon"), style: .done, target: self, action: #selector(didTapOnBack))
self.navigationItem.leftBarButtonItem = backButtonItem

Daniel Storm
- 18,301
- 9
- 84
- 152

Roja
- 1
- 2
-
Welcome to Stack Overflow! While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please [include an explanation for your code](//meta.stackexchange.com/q/114762/269535), as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Samuel Philipp Jul 08 '19 at 14:59