On iOS 7, when the tint color changes (for example, when a UIAlertView is presented), views are notified in their tintColorDidChange
method.
I have a few subviews for which I'd like to provide a customized disabled state. (For example, say I'd like to also temporarily dim the backgroundColor
of a custom UIControl.)
I had been using this code:
- (void)tintColorDidChange {
BOOL isInactive = (CGColorSpaceGetModel(CGColorGetColorSpace([self.tintColor CGColor])) == kCGColorSpaceModelMonochrome);
if (isInactive) {
// modify subviews to look disabled
} else {
// modify subviews to look enabled
}
}
However, on some views in one of my apps, the active tint color is a very dark gray, and the inactive tint color is a lighter gray.
In this case, both colors report as "inactive" because both colors are monochrome.
Is there a better test to determine if the current state is active or dimmed?
Have a look at the UIView tintAdjustmentMode
property. Something like this (in your custom control class):
- (void)tintColorDidChange {
BOOL isInactive = self.tintAdjustmentMode == UIViewTintAdjustmentModeDimmed;
if (isInactive) {
// modify subviews to look disabled
} else {
// modify subviews to look enabled
}
}
Of course this code must only be run under iOS 7.0 or later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With