我想在禁用时隐藏按钮的边框。启用后,我这样设置边框:
_btnInit.layer.borderWidth = 1;
_btnInit.layer.borderColor = [[UIColor grayColor]CGColor];
如图所示。左侧为禁用状态,右侧为正常状态。
最佳答案
子类化 UIButton 并像这样覆盖 isEnabled 属性,
override var isEnabled: Bool {
didSet {
if isEnabled {
self.layer.borderColor = UIColor.black.cgColor
self.layer.borderWidth = 1.0
} else {
self.layer.borderWidth = 0.0
}
}
}
关于ios - 禁用时更改 UIButton 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49045324/