ale*_*wis 1 uibutton ios swift
我有一个UIButton生成如下的子类:
class MoreOptionsButton: UIButton {
override func draw(_ rect: CGRect) {
let path = UIBezierPath(ovalIn: rect)
UIColor.red.setFill()
path.fill()
let r = CGRect(x: rect.width * 0.5 - rect.width * 0.15 * 0.5, y: rect.height * 0.5 - rect.height * 0.15 * 0.5, width: rect.width * 0.15, height: rect.height * 0.15)
var circlePath = UIBezierPath(ovalIn: r)
UIColor.white.setFill()
circlePath.fill()
circlePath = UIBezierPath(ovalIn: r.offsetBy(dx: -rect.width / 4.0, dy: 0.0))
UIColor.white.setFill()
circlePath.fill()
circlePath = UIBezierPath(ovalIn: r.offsetBy(dx: rect.width / 4.0, dy: 0.0))
UIColor.white.setFill()
circlePath.fill()
}
}
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
但是,当我在模拟器中按下此按钮时,它不会像普通System类型按钮那样自动调暗.请问如何达到这个效果?
在UIButton自定义类中添加以下代码:
override var isHighlighted: Bool {
didSet {
alpha = isHighlighted ? 0.4 : 1
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
206 次 |
| 最近记录: |