Reputation: 2894
when disable button. opacity reduced to 50% .is there any way to reduce opacity to 25%
Upvotes: 1
Views: 1082
Reputation: 14328
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)
}
}
}
Upvotes: 0
Reputation: 3300
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];
}
}
Upvotes: 4