I want to personalize the Back Button of my app to have a consistent looking. So I'm setting a image as the Back Button of a Navigation Bar.
The code bellow works fine on any iOS above iOS 10. So, I'm trying to make it work on iOS 10.3.1.
This is basically all the code, that I'm setting on AppDelegate didFinishLaunchingWithOptions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
applyNavigationAppearances()
return true
}
private func applyNavigationAppearances() {
let navigationAppearance = UINavigationBar.appearance()
navigationAppearance.barTintColor = .white
navigationAppearance.barStyle = .black
navigationAppearance.backIndicatorImage = UIImage()
navigationAppearance.backIndicatorTransitionMaskImage = UIImage()
navigationAppearance.tintColor = .gray
navigationAppearance.titleTextAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.gray,
NSAttributedString.Key.font: UIFont(name: "Helvetica-Bold", size: 20)
]
let backImage = UIImage(named: "chevron-orange-left")
let backImageUIEdgeInsets = UIEdgeInsets(top: -4, left: -8, bottom: -2, right: 8)
let backImageWithAlignmentRectInsets = backImage?.withAlignmentRectInsets(backImageUIEdgeInsets)
let barButtonAppearance = UIBarButtonItem.appearance()
barButtonAppearance.setBackButtonBackgroundVerticalPositionAdjustment(-1.0, for: .default)
barButtonAppearance.setBackButtonBackgroundImage(backImageWithAlignmentRectInsets, for: .normal, barMetrics: .default)
}
This is what I want and get on any iOS above 10:
This is what I get on iOS 10.3.1:
Edit 1: It's worth saying this is a big app. A solution that didn't involved changing every ViewController would be ideal.
Edit 2: Thank you for answer guys. However, all solutions posted here are distorting the image shorter or longer, so they don't quite solve my problem.