-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExaminationModalityView.swift
137 lines (111 loc) · 4.29 KB
/
ExaminationModalityView.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// ExaminationModalityView.swift
// dogether
//
// Created by seungyooooong on 2/17/25.
//
import Foundation
import UIKit
import SnapKit
final class ExaminationModalityView: UIView {
var buttonAction: (FilterTypes) -> Void
private var review: ReviewModel
init(buttonAction: @escaping (FilterTypes) -> Void, review: ReviewModel) {
self.buttonAction = buttonAction
self.review = review
super.init(frame: .zero)
setUI()
}
required init?(coder: NSCoder) { fatalError() }
private var imageView = UIImageView()
private let contentLabel = {
let label = UILabel()
label.textColor = .grey0
label.numberOfLines = 0
return label
}()
private func examinationButton(type: FilterTypes) -> UIButton {
let button = UIButton()
button.backgroundColor = .grey0
button.layer.cornerRadius = 8
button.tag = type.tag
button.addTarget(self, action: #selector(didTapExaminationButton(_:)), for: .touchUpInside)
let icon = UIImageView(image: type.image?.withRenderingMode(.alwaysTemplate))
icon.tintColor = .grey700
let label = UILabel()
label.text = type.rawValue
label.textColor = .grey700
label.font = Fonts.body1S
let stackView = UIStackView(arrangedSubviews: [icon, label])
stackView.axis = .horizontal
stackView.spacing = 8
stackView.isUserInteractionEnabled = false
[stackView].forEach { button.addSubview($0) }
stackView.snp.makeConstraints {
$0.center.equalToSuperview()
}
icon.snp.makeConstraints {
$0.width.height.equalTo(type == .reject ? 22 : 24) // MARK: 임의로 사이즈 조정
}
return button
}
private var rejectButton = UIButton()
private var approveButton = UIButton()
private func examinationStackView(buttons: [UIButton]) -> UIStackView {
let stackView = UIStackView(arrangedSubviews: buttons)
stackView.axis = .horizontal
stackView.spacing = 11
stackView.distribution = .fillEqually
return stackView
}
private var examinationStackView = UIStackView()
private func setUI() {
backgroundColor = .grey800
layer.cornerRadius = 12
// TODO: 추후 수정
imageView = CertificationImageView(
image: .logo,
certificationContent: review.content,
certificator: review.doer
)
contentLabel.attributedText = NSAttributedString(
string: review.todoContent,
attributes: Fonts.getAttributes(for: Fonts.head2B, textAlignment: .center)
)
rejectButton = examinationButton(type: .reject)
approveButton = examinationButton(type: .approve)
examinationStackView = examinationStackView(buttons: [rejectButton, approveButton])
[imageView, contentLabel, examinationStackView].forEach { addSubview($0) }
self.snp.updateConstraints {
$0.height.equalTo(487)
}
imageView.snp.makeConstraints {
$0.top.equalToSuperview().offset(24)
$0.horizontalEdges.equalToSuperview().inset(20)
$0.height.equalTo(303)
}
contentLabel.snp.makeConstraints {
$0.top.equalTo(imageView.snp.bottom).offset(16)
$0.horizontalEdges.equalToSuperview().inset(20)
$0.height.equalTo(56)
}
examinationStackView.snp.makeConstraints {
$0.top.equalTo(contentLabel.snp.bottom).offset(16)
$0.horizontalEdges.equalToSuperview().inset(20)
$0.height.equalTo(48)
}
}
@objc private func didTapExaminationButton(_ sender: UIButton) {
guard let type = FilterTypes.allCases.first(where: { $0.tag == sender.tag }) else { return }
rejectButton.backgroundColor = type == .reject ? .dogetherRed : .grey0
approveButton.backgroundColor = type == .approve ? .blue300 : .grey0
switch type {
case .reject:
buttonAction(type)
case .approve:
buttonAction(type)
default:
return
}
}
}