Search code examples
iosnsnotificationcentertintcolor

Trigger tintColorDidChange to desaturate tinted elements in response to user action


You can override tintColorDidChange in a UIView subclass and access the tintAdjustmentMode in order to know when iOS is going to desaturate your elements when an alert is shown for example.

I am implementing a custom modal control that should cause iOS to desaturate the underlying views. How can I trigger that, is there a notification I can post?

I can manually set the tint color to UIColor(white: 128/255, alpha: 1) in order to fake this, then reset it when appropriate, but this is a poor workaround as it's not truly desaturating the elements, instead just applying a different tint color.


Solution

  • You could set the window's tintAdjustmentMode to UIViewTintAdjustmentModeDimmed and then set the alert's tintAdjustmentMode to UIViewTintAdjustmentModeNormal.