-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquareButton.swift
49 lines (40 loc) · 1.21 KB
/
SquareButton.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// SquareButton.swift
// HW42-HSR(PickerVeiw)
//
// Created by Dawei Hao on 2024/3/2.
//
import UIKit
class SquareButton: UIButton {
// Property to hold the click count
private var clickCount = 0
override init(frame: CGRect) {
super.init(frame: frame)
setupButton()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupButton()
}
private func setupButton() {
// Add target for touch up inside action
self.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
// Initial button image
updateSquareButtonImage()
}
@objc private func buttonTapped() {
// Increment click count
clickCount += 1
// Update button image based on click count
updateSquareButtonImage ()
}
private func updateSquareButtonImage() {
// Determine the button image based on click count
// This is a simplified example; you can customize the logic as needed
if clickCount.isMultiple(of: 2) {
self.setImage(Images.square, for: .normal)
} else {
self.setImage(Images.checkmarkSquare, for: .normal)
}
}
}