I have been using this code to change the tint color of element in the navigation bar:
UINavigationBar.appearance().tintColor = theme.labelColor
However, this is no longer working in iOS 11. Before iOS 11, buttons in the Navigation Bar were UINavigationButton
s, but in iOS 11 they've been changed to _UIModernBarButton
. I was able to change their tint color with UIButton.appearance().tintcolor
, but that changes every button's.
Here's a comparison:
Anyone has any idea how to change the button tint color in the navigation bar?
UPDATE 01/09/2017:
Looks like _UIButtonBarButton
has the correct tint color, but _UIModernBarButton
overwrites it with the color set for UIButton
.
UPDATE 18/09/2017:
"Engineering has provided the following feedback regarding this issue:
UIView.tintColor is not an appearance selector, and specifically is documented as not working correctly as an appearance property due to its inheritance properties."
Open the project's storyboard file. Select the UINavigationBar from your UINavigationController scene. In the Attributes Inspector pane turn on these Appearances: “Standard”, “Compact”, “Scroll Edge”, and “Compact Scroll Edge”. For all four appearances, set the “Background” to “System Red Color”, for example.
A color used to tint template images in the view hierarchy.
So I did find kind of a solution. I am setting the tint color via the appearance proxy for UIButton but only when contained in an UINavigationBar. This looks like it is working for me. However still hoping that this behaviour will change in the iOS 11 GM or someone can come up with a better solution. Here is my working code:
if([UIButton respondsToSelector:@selector(appearanceWhenContainedInInstancesOfClasses:)]) {
[[UIButton appearanceWhenContainedInInstancesOfClasses:@[UINavigationBar.class]]setTintColor:navTintColor];
}
Swift version of appearance proxy call:
UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = UIColor.red
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With