6
votes

Xcode Version 11.0 beta 5 (11M382q)

I'm using the new appearance APIs to tint the color of the bar button items when one of my view controllers is the top view controller. I'm using the following code to do so:

let appearance = UINavigationBarAppearance()
let attributes: [NSAttributedString.Key : Any] = [.foregroundColor : tintColor]

appearance.largeTitleTextAttributes = attributes
appearance.buttonAppearance.normal.titleTextAttributes = attributes
appearance.doneButtonAppearance.normal.titleTextAttributes = attributes

navigationItem.standardAppearance = appearance

This seems to work fine for text-based bar button items, but the image based bar button items maintain the app's default tint. Is this a bug in iOS 13 beta? I've logged a radar, but just wanted to see if anyone else has encountered this or found a workaround.

As you can see below, the back arrow and the plus button are not the right color.

Screenshot displaying incorrect bar button item tint

3
Any luck with this? Also having this problem and no idea where to go from here.HarryGThompson
Unfortunately I haven’t figured out what’s causing this.Mark

3 Answers

0
votes

This is simply a case of not setting the following:

UINavigationBar.appearance().barTintColor = UIColor.black
UINavigationBar.appearance().tintColor = UIColor.white

I had not set these as I thought the new UINavigationBarAppearance() replaced them but setting these fixes the issue. I think this will be updated in either the GM or a future version though as it seems odd to use a mix of new and old API's.

0
votes

You have to set:

let backImage = appearance.backIndicatorImage.tint(with: tintColor)
appearance.setBackIndicatorImage(backImage, transitionMaskImage: backImage)
0
votes

After much trial and error, I finally got this working:

UIImage *image = [[[UIImage systemImageNamed:@"chevron.left" withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]] imageWithTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationController.navigationBar.backIndicatorImage = image;
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = image;

But of course this isn't working in iOS 15.