ZhgChg.Li

iOS tintAdjustmentMode|Fix UIImageAsset .tintColor Failure in UIAlertController

iOS developers facing .tintColor failure on Image Assets rendered as template during UIAlertController presentation can resolve this with tintAdjustmentMode tweaks, restoring expected UI color behavior efficiently.

iOS tintAdjustmentMode|Fix UIImageAsset .tintColor Failure in UIAlertController

iOS tintAdjustmentMode Property

Present UIAlertController Causes Image Assets (Render as Template) .tintColor Setting to Fail on Current Page

Comparison Before and After Issue Fix

No fuss, just go straight to the comparison chart.

Before Correction/After Correction

Left: Before correction / Right: After correction

You can see that the tintColor setting for the left icon fails when presenting a UIAlertController. However, the color setting returns to normal after the presented view is dismissed.

Issue Fixes

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

  1. .Automatic: The view’s tintAdjustmentMode follows the setting of its enclosing parent view

  2. .Normal: Default mode, displays the assigned tintColor normally

  3. .Dimmed: Changes tintColor to a low-saturation, dim color (which is gray!)

The above issue is not a bug but rather the inherent mechanism of the system:

When presenting a UIAlertController, the tintAdjustmentMode of the Root ViewController’s view on the current page changes to Dimmed (so technically, the color setting is not “disabled,” but the tintAdjustmentMode is altered)

Sometimes, if we want the ICON color to remain consistent, we only need to keep the tintAdjustmentMode the same 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 not changed, but it is just annoying to look at.

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

I searched for a while and found that it is related to this property. After setting it, my small doubt was resolved.

Improve this page
Edit on GitHub
Originally published on Medium
Read the original
Share this essay
Copy link · share to socials
ZhgChgLi
Author

ZhgChgLi

An iOS, web, and automation developer from Taiwan 🇹🇼 who also loves sharing, traveling, and writing.

Comments

Powered by giscus