Home iOS tintAdjustmentMode Property

iOS tintAdjustmentMode Property

iOS tintAdjustmentMode Property

Issue with .tintColor setting failing when presenting UIAlertController on this page’s Image Assets (Render as template)

Comparison Before and After Fix

No lengthy explanations, let’s go straight to the comparison images.

Left Before Fix/Right After Fix

Left Before Fix/Right After Fix

You can see that the ICON on the left loses its tintColor setting when UIAlertController is presented. Additionally, the color setting returns to normal once the presented window is closed.

Issue Fix

First, let’s introduce the tintAdjustmentMode property. This property controls the display mode of tintColor and has three enumeration settings:

  1. .Automatic: The view’s tintAdjustmentMode is consistent with the enclosing parent view’s setting.
  2. .Normal: Default mode, displays the set tintColor normally.
  3. .Dimmed: Changes tintColor to a low saturation, dim color (basically gray!).

The above issue is not a bug but a system mechanism:

When presenting UIAlertController, it changes the tintAdjustmentMode of the Root ViewController’s view to Dimmed (so technically, the color setting doesn’t “fail”; it’s just that the tintAdjustmentMode mode changes).

But sometimes we want the ICON color to remain consistent, so we just need to keep the tintAdjustmentMode setting consistent in the UIView’s tintColorDidChange event:

extension UIButton { 
   override func tintColorDidChange() {
        self.tintAdjustmentMode = .normal // Always keep normal

extension example

The End!

It’s not a big issue, and it’s fine if you don’t change it, but it can be an eyesore.

Actually, every page that encounters presenting UIAlertController, action sheet, popover, etc., will change the view’s tintAdjustmentMode to gray, but I only noticed it on this page.

After searching for a while, I found out it was related to this property. Setting it resolved my small confusion.

If you have any questions or feedback, feel free to contact me.




This article was first published in Traditional Chinese on Medium ➡️ View Here

This post is licensed under CC BY 4.0 by the author.

Let's Build an Apple Watch App!

Identify Your Own Calls (Swift)