Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBarAppearance not working for image based bar button items

Tags:

ios

swift

ios13

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

like image 763
Mark Avatar asked Aug 24 '19 03:08

Mark


1 Answers

You have to set:

let backImage = appearance.backIndicatorImage.tint(with: tintColor)
appearance.setBackIndicatorImage(backImage, transitionMaskImage: backImage)
like image 50
RiccardoCh Avatar answered Nov 02 '22 17:11

RiccardoCh