ios - 按下时如何突出显示按钮,例如swift中的ios13计算器?
问题描述
我在一个快速项目中创建了一个按钮,现在我想让我的按钮在按下时发光,就像在 ios13 中的苹果计算器中发生的那样,我使用 button.showsTouchWhenHighlighted = true
了但这不是我想要的。
解决方案
您必须覆盖自定义 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")
}
}
推荐阅读
- c++ - OpenCL 访问共享本地内存
- networking - 我可以在具有两个 100GbE 端口的网卡上处理多少传入流量?
- laravel - 如何在 laravel 7 中将 1000 显示为 1k
- python - 在 if 函数中组合布尔测试
- c# - System.InvalidOperationException:ExecuteReader 需要打开且可用的连接。连接的当前状态为打开
- ios - 获取最新版本的 Firebase Cocoapods 时出现问题
- postgresql - 仅使用子查询而不使用 JOIN
- shell - 是否可以从 troff 格式制作手册页?
- c++ - 分配的内存和保留的内存有什么区别?
- php - 纠正 PHPStan 在 Symfony 项目的 UserInterface 上抛出的类型提示错误