[英]iOS (Swift): Dimming UIButton when pressed
我有一個生成的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()
}
}
看起來像這樣:
但是,當我按下模擬器中的此按鈕時,它不會像正常的“ System
類型”按鈕那樣自動變暗。 請問我如何達到這種效果?
有兩種按鈕選擇狀態和未選擇狀態,您可以為這兩種狀態分配圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.