为什么我的 UIButtons 在 iOS 7 中会在控制器转换时改变颜色?

Why do my UIButtons change color in iOS 7 upon controller transition?

所以我有一些 UIButton。正如我所料,启用时它们是蓝色的,禁用时是灰色的。

如果我从我的首页转到当前竞赛并且出现这样的网络错误:

我调用 [self.navigationController popViewControllerAnimated:YES]; 返回主页,我在 iOS 7, iPhone 4:

灰色按钮,但它们有效。所以我知道他们没有残疾。这不会发生在 iOS 8, iPad Mini.

您可以使用在 iOS 7 中介绍的 tintAdjustmentMode 属性 解决此问题:

When this property’s value is UIViewTintAdjustmentModeDimmed, the value of the tintColor property is modified to provide a dimmed appearance.

If the system cannot find a non-default value in the subview hierarchy when you query this property, the value is UIViewTintAdjustmentModeNormal.

When this property’s value changes (either by the view’s value changing or by one of its superview’s values changing), -the system calls the tintColorDidChange method to allow the view to refresh its rendering.

- from the UIView Class Reference.

当某些叠加视图(例如 UIAlertView 等)变得可见时,它们实质上会将此 属性 更改为 UIViewTintAdjustmentModeDimmed。您可以通过为整个 UIWindow(以及子视图层次结构)设置 tintAdjustmentMode 来解决此问题:

self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;