在Disabale UIButton上

当禁用button。 不透明度降低到50%,有什么办法可以将不透明度降低到25%

我会inheritanceUIButton并覆盖setEnabled:方法如下所示:

 - (void) setEnabled:(BOOL)enabled { NSLog(@"Button enabled = %d", enabled); [super setEnabled:enabled]; UIColor *color = self.backgroundColor; if (!self.isEnabled) { self.backgroundColor = [color colorWithAlphaComponent:0.75]; } else { self.backgroundColor = [color colorWithAlphaComponent:1.0]; } } 

杰克·考克斯的答案是:

 override var enabled: Bool{ didSet { if enabled { self.backgroundColor = self.backgroundColor?.colorWithAlphaComponent(1) } else { self.backgroundColor = self.backgroundColor?.colorWithAlphaComponent(0.75) } } }