on Disabale UIButton
when disable button. opacity reduced to 50% .is there any way 开发者_StackOverflow社区to reduce opacity to 25%
I would subclass UIButton and override the setEnabled: method to something like this:
- (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];
}
}
the swift version of Jack Cox's answer is:
override var enabled: Bool{
didSet {
if enabled {
self.backgroundColor = self.backgroundColor?.colorWithAlphaComponent(1)
} else {
self.backgroundColor = self.backgroundColor?.colorWithAlphaComponent(0.75)
}
}
}
精彩评论