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.
点击这里查看本文章简体中文版本。
點擊這裡查看本文章正體中文版本。
This post was translated with AI assistance — let me know if anything sounds off!
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.
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:
.Automatic: The view’s tintAdjustmentMode follows the setting of its enclosing parent view
.Normal: Default mode, displays the assigned tintColor normally
.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:
1
2
3
4
5
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.
If you have any questions or feedback, feel free to contact me.
This post was originally published on Medium (View original post), and automatically converted and synced by ZMediumToMarkdown.