开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜