iOS13 UIButton tint misbehaving

Hello,


In my app, I have several System UIButtons with an image (Template Image) and tint colour. I am dynamically setting the buttons tint colour in viewDidLoad. The result is a button with an icon that have the same colour.

This works amazingly in all iOS versions prior to 13.


self.button.tintColor = tintColor;


On iOS13 and iOS13.1 it only works sometimes, so far I have not been able to diagnose why.

Instead of getting a button with an icon that are the same colour, I am getting a button that is the expected colour and an icon that is the default tint colour (blue).

The implementation of the buttons is the same in all view controllers but the unwanted behaviour only appears in some of the view controllers consistently.


The following code snipet fixes the unwanted behaviour in a number of view controllers, but not everywhere.

dispatch_async(dispatch_get_main_queue(), ^{
     self.button.tintColor = tintColor;
});


The following code snipet seems to fix the unwanted behaviour everywhere:

self.button.tintColor = tintColor;
self.button.imageView.tintColor = tintColor;


I have tested it on both simulators and devices.

My question is what is causing this behaviour, is it expected? Am I doing something wrong?

Can you show how tintColor is defined ?


Is it a custom color or a system color ?

Does it occur in light or dark mode or both ?


Did you watch WWDC video for the colors matter ?

https://developer.apple.com/videos/play/wwdc2019/214/

at about 9'

Hey Claude31,


My tint colour is hardcoded. I have tried defining tint colour like:

UIColor *tintColor = UIColor.redColor;

or like:

UIColor *tintColor = [UIColor colorWithHex:0xFF017FAF];

They both result in the same outcome.


All my testing so far has been done in Light mode.

I just had a quick check in Dark mode - the button and the icon still apear in different colours.

Could you test using systemColors ?


UIColor *tintColor = UIColor.systemRedColor;



Is the button a of custom type ?

If so, the following could explain the problem

What type of image is the icon ?


Instance PropertytintColor


The tint color to apply to the button title and image.


Declaration

var tintColor: UIColor! { get set }

Discussion

All subclasses of

UIView
derive their behavior for
tintColor
from the base class. See the discussion of
tintColor
at the
UIView
level for more information.

This property has no default effect for buttons with type

UIButton.ButtonType.custom
. For custom buttons, you must implement any behavior related to
tintColor
yourself.



This WWDC 2018 could also be interesting

https://developer.apple.com/videos/play/wwdc2018/218/

look at 8'45

Hey, thanks for your reply.


Using systemColors fixes the issue, but I cannot use those colours in the production version of the app (We are using custom/dynamically defined colours, the red was used for debuging as it has high contrast against the system blue colour).


The buton is not custom type, it is system type.


The icon is a 16x16 .pdf (vector), that is set to render as a template image.

If systemColors work you are on the good track.


You should define your own colors in Assets and use them as you use system ones.


Have a look at WWDC 2019 session on DarkMode for iOS, they explain it pretty well (I think I remember it is session 210).

The tint color of the button will be as per that set in tye tintColor property of the UIImageView and not the tintColor property of the UIButton.
iOS13 UIButton tint misbehaving
 
 
Q