我在一个快速项目中创建了一个按钮,现在我想让它的按钮像iOS 13中苹果计算器中发生的那样按下时发光,我使用了button.showsTouchWhenHighlighted = true
,但这不是我想要的。
如何在按下按钮时高亮显示按钮,如快速地更改ios13计算器?
•
问答
dilixinxi123 回答:如何在按下按钮时高亮显示按钮,如快速地更改ios13计算器?
您可以将How to Connect Google Cloud Memorystore with App Engine Standard设置为true
:
button.adjustsImageWhenHighlighted = true
或者如果不够好,则可以通过adjustsImageWhenHighlighted为.highlighted
状态添加另一张图片:
button.setBackgroundImage(lighBackgroundImage,for: .highlighted)
您也可以在界面生成器中执行此操作。
,您必须像下面这样重写自定义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")
}
}