检查tintColor是否在tintColorDidChange中变暗 [英] Check if tintColor is dimmed in tintColorDidChange

查看:247
本文介绍了检查tintColor是否在tintColorDidChange中变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 7中,当颜色变化时(例如,当显示UIAlertView时),会在其 tintColorDidChange 方法中通知视图。

On iOS 7, when the tint color changes (for example, when a UIAlertView is presented), views are notified in their tintColorDidChange method.

我有几个子视图,我想提供一个自定义的禁用状态。 (例如,我想要暂时调暗自定义UIControl的 backgroundColor 。)

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已使用此代码:

- (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?

推荐答案

看看 UIView tintAdjustmentMode 属性。这样的东西(在你的自定义控件类):

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
    }
}

当然,此代码只能在iOS 7.0或更高版本中运行。

Of course this code must only be run under iOS 7.0 or later.

这篇关于检查tintColor是否在tintColorDidChange中变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆