Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right way to set back button arrow tint in ios 13

In ios 13, Apple introduced the new UINavigationBarAppearance proxy object to set the navigation bar appearance. I've been able to set almost everything I needed except one small thing. The back button's arrow is always rendered with blue tint color and I have no idea how to set it to the color I want. I am using the old [[UINavigationBar appearance] setTintColor:] way, but I think there has to be some way to do it with the UINavigationBarAppearance objects API. Anybody has any idea how?

like image 739
Roman Avatar asked Sep 30 '19 13:09

Roman


1 Answers

The new way of setting the back button color of the appearance (proxy) would be:

let appearance = UINavigationBarAppearance()

// Apply the configuration option of your choice
appearance.configureWithTransparentBackground()
            
// Create button appearance, with the custom color
let buttonAppearance = UIBarButtonItemAppearance(style: .plain)
buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]

// Apply button appearance
appearance.buttonAppearance = buttonAppearance

// Apply tint to the back arrow "chevron"
UINavigationBar.appearance().tintColor = UIColor.white

// Apply proxy
UINavigationBar.appearance().standardAppearance = appearance

// Perhaps you'd want to set these as well depending on your design:
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
like image 144
Justin Ganzer Avatar answered Dec 10 '22 19:12

Justin Ganzer