-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDateView.swift
More file actions
130 lines (110 loc) · 4.2 KB
/
DateView.swift
File metadata and controls
130 lines (110 loc) · 4.2 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
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
//
// DateView.swift
// Presentation
//
// Created by 최정인 on 7/23/25.
//
import Shared
import SnapKit
import UIKit
final class DateView: UIView {
private enum Layout {
static let dateButtonCornerRadius: CGFloat = 8
static let dayLabelHeight: CGFloat = 18
static let dateButtonTopSpacing: CGFloat = 7
static let dateButtonSize: CGFloat = 30
static let dateLabelHeight: CGFloat = 17
static let allCompletedIconTopSpacing: CGFloat = 5
}
private let dayLabel = UILabel()
private let dateButton = UIButton()
private let dateLabel = UILabel()
private let allCompletedIcon = UIImageView()
private let date: Date
private let isToday: Bool
private var isSelected: Bool {
didSet {
updateAttribute()
}
}
var didTapDateButton: ((Date) -> Void)?
init(
date: Date,
isSelected: Bool = false,
isToday: Bool = false
) {
self.date = date
self.isToday = isToday
self.isSelected = isSelected
super.init(frame: .zero)
configureAttribute()
configureLayout()
updateAttribute()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func configureAttribute() {
dayLabel.text = isToday ? "오늘" : "\(date.convertToString(dateType: .dayOfWeek))"
dayLabel.font = BitnagilFont(style: .caption1, weight: .medium).font
dayLabel.textColor = BitnagilColor.gray70
dayLabel.textAlignment = .center
dateButton.backgroundColor = .white
dateButton.layer.masksToBounds = true
dateButton.layer.cornerRadius = Layout.dateButtonCornerRadius
dateButton.addAction(
UIAction { [weak self] _ in
self?.selectDate()
},
for: .touchUpInside)
dateLabel.text = "\(date.convertToString(dateType: .date))"
dateLabel.font = BitnagilFont(style: .body2, weight: .medium).font
dateLabel.textColor = BitnagilColor.gray70
allCompletedIcon.image = BitnagilIcon.asteriskIcon
allCompletedIcon.isHidden = true
}
private func configureLayout() {
addSubview(dayLabel)
addSubview(dateButton)
dateButton.addSubview(dateLabel)
addSubview(allCompletedIcon)
dayLabel.snp.makeConstraints { make in
make.top.leading.trailing.equalToSuperview()
make.height.equalTo(Layout.dayLabelHeight)
make.width.equalTo(dateButton.snp.width)
}
dateButton.snp.makeConstraints { make in
make.top.equalTo(dayLabel.snp.bottom).offset(Layout.dateButtonTopSpacing)
make.horizontalEdges.equalTo(dayLabel)
make.size.equalTo(Layout.dateButtonSize)
}
dateLabel.snp.makeConstraints { make in
make.center.equalToSuperview()
make.height.equalTo(Layout.dateLabelHeight)
}
allCompletedIcon.snp.makeConstraints { make in
make.top.equalTo(dateButton.snp.bottom).offset(Layout.allCompletedIconTopSpacing)
make.centerX.equalToSuperview()
}
}
private func updateAttribute() {
let selectedDayLabelFont = BitnagilFont(style: .caption1, weight: .semiBold).font
let deselectedDayLabelFont = BitnagilFont(style: .caption1, weight: .medium).font
dayLabel.font = isSelected ? selectedDayLabelFont : deselectedDayLabelFont
dayLabel.textColor = isSelected ? BitnagilColor.gray10 : BitnagilColor.gray70
let selectedDateLabelFont = BitnagilFont(style: .body2, weight: .semiBold).font
let deselectedDateLabelFont = BitnagilFont(style: .body2, weight: .medium).font
dateLabel.font = isSelected ? selectedDateLabelFont : deselectedDateLabelFont
dateLabel.textColor = isSelected ? .white : BitnagilColor.gray70
dateButton.backgroundColor = isSelected ? BitnagilColor.gray10 : .clear
}
private func selectDate() {
didTapDateButton?(date)
}
func updateSelectState(isSelected: Bool) {
self.isSelected = isSelected
}
func updateAllCompleted(isCompleted: Bool) {
allCompletedIcon.isHidden = !isCompleted
}
}