我在一个swift项目中创建了一个按钮,现在我想让我的按钮在按下时发光,就像在ios13中苹果的计算器中发生的那样,我使用了button.showsTouchWhenHighlighted = true,但这不是我想要的。
发布于 2019-11-06 19:27:22
您可以将adjustsImageWhenHighlighted设置为true
button.adjustsImageWhenHighlighted = true或者,如果这还不够好,可以通过setBackgroundImage为.highlighted状态添加另一个映像
button.setBackgroundImage(lighBackgroundImage, for: .highlighted)您也可以在接口构建器中执行此操作。
发布于 2019-11-06 19:35:05
必须覆盖自定义UIButton类中的isSelected属性,如下所示:
override var isSelected: Bool {
didSet {
updateState(state: isSelected)
}
}
func updateState(state: Bool) {
if state == false {
self.layer.borderWidth = 0.0
self.layer.borderColor = UIColor.red.cgColor
print("false")
} else if state == true {
self.layer.borderWidth = 3.0
self.layer.borderColor = UIColor.blue.cgColor
print("true")
}
}https://stackoverflow.com/questions/58728696
复制相似问题