-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrimaryButton.swift
More file actions
69 lines (59 loc) · 1.74 KB
/
PrimaryButton.swift
File metadata and controls
69 lines (59 loc) · 1.74 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// PrimaryButton.swift
// Presentation
//
// Created by 최정인 on 7/6/25.
//
import UIKit
final class PrimaryButton: UIButton {
enum ButtonState {
case `default`
case hover
case pressed
case disabled
var buttonColor: UIColor? {
switch self {
case .default: BitnagilColor.gray10
case .hover: BitnagilColor.gray5
case .pressed: BitnagilColor.gray5
case .disabled: BitnagilColor.gray95
}
}
var buttonTextColor: UIColor? {
switch self {
case .default: .white
case .hover: .white
case .pressed: BitnagilColor.gray20
case .disabled: .white
}
}
}
private var buttonState: ButtonState {
didSet {
updateButtonUI()
}
}
init(buttonState: ButtonState, buttonTitle: String) {
self.buttonState = buttonState
super.init(frame: .zero)
configureAttribute(buttonTitle: buttonTitle)
self.isEnabled = buttonState != .disabled
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func updateButtonState(buttonState: ButtonState) {
self.buttonState = buttonState
self.isEnabled = buttonState != .disabled
}
private func configureAttribute(buttonTitle: String) {
setTitle(buttonTitle, for: .normal)
titleLabel?.font = BitnagilFont(style: .body1, weight: .semiBold).font
layer.cornerRadius = 12
updateButtonUI()
}
private func updateButtonUI() {
setTitleColor(buttonState.buttonTextColor, for: .normal)
backgroundColor = buttonState.buttonColor
}
}