@@ -11,19 +11,27 @@ import UIKit
1111
1212final class RoutineView : UIView {
1313 private enum Layout {
14- static let timeLabelHeight : CGFloat = 20
14+ static let horizontalMargin : CGFloat = 16
15+ static let routineContentStackViewSpacing : CGFloat = 10
16+ static let routineContentStackViewVerticalMargin : CGFloat = 10
17+ static let timeLabelWidth : CGFloat = 42
18+ static let containerViewLeadingSpacing : CGFloat = 8
19+ static let mainRoutineViewHeight : CGFloat = 28
20+ static let mainRoutineLabelTrailingSpacing : CGFloat = 10
21+ static let mainRoutineCheckButtonSize : CGFloat = 28
22+ static let grayLineHeight : CGFloat = 1
23+ static let subRoutineViewHeight : CGFloat = 24
24+ static let subRoutineLabelLeadingSpacing : CGFloat = 10
25+ static let subRoutineCheckButtonSize : CGFloat = 24
1526 }
1627
1728 private let timeLabel = UILabel ( )
1829 private let containerView = UIView ( )
30+ private let routineContentStackView = UIStackView ( )
1931 private let mainRoutineView = UIView ( )
2032 private let mainRoutineLabel = UILabel ( )
2133 private let mainRoutineCheckButton = UIButton ( )
2234 private let grayLine = UIView ( )
23- private let subRoutineStackView = UIStackView ( )
24-
25- private var isLayoutConfigured : Bool = false
26- private var mainRoutineHeightConstraint : Constraint ?
2735 private var routine : Routine {
2836 didSet {
2937 updateRoutineState ( )
@@ -41,36 +49,30 @@ final class RoutineView: UIView {
4149 fatalError ( " init(coder:) has not been implemented " )
4250 }
4351
44- override func layoutSubviews( ) {
45- super. layoutSubviews ( )
46-
47- guard !isLayoutConfigured else { return }
48- isLayoutConfigured = true
49- }
50-
51- override var intrinsicContentSize : CGSize {
52- var baseHeight : CGFloat = 56
53- if !routine. subRoutines. isEmpty {
54- baseHeight = 100
55- baseHeight += ( 34.0 * CGFloat( routine. subRoutines. count - 1 ) )
56- }
57- return CGSize ( width: UIView . noIntrinsicMetric, height: baseHeight)
58- }
59-
6052 private func configureAttribute( ) {
61- timeLabel. text = routine. startTime. convertToString ( dateType: . time24hour)
53+ var timeLabelText = routine. startTime. convertToString ( dateType: . time24hour)
54+ if timeLabelText == " 00:00 " {
55+ timeLabelText = " 하루 종일 "
56+ }
57+ timeLabel. text = timeLabelText
6258 timeLabel. font = BitnagilFont ( style: . body2, weight: . medium) . font
6359 timeLabel. textColor = BitnagilColor . gray10
60+ timeLabel. numberOfLines = 2
6461
6562 containerView. backgroundColor = . white
6663 containerView. layer. masksToBounds = true
6764 containerView. layer. cornerRadius = 12
6865
66+ routineContentStackView. axis = . vertical
67+ routineContentStackView. spacing = Layout . routineContentStackViewSpacing
68+
6969 mainRoutineLabel. text = routine. title
7070 mainRoutineLabel. font = BitnagilFont ( style: . body1, weight: . semiBold) . font
7171 mainRoutineLabel. textColor = BitnagilColor . gray10
72+ mainRoutineLabel. numberOfLines = 0
7273
73- mainRoutineCheckButton. setImage ( BitnagilIcon . uncheckedCircleIcon, for: . normal)
74+ let mainRoutineCheckIcon = routine. isDone ? BitnagilIcon . checkedCircleIcon : BitnagilIcon . uncheckedCircleIcon
75+ mainRoutineCheckButton. setImage ( mainRoutineCheckIcon, for: . normal)
7476 mainRoutineCheckButton. addAction (
7577 UIAction { [ weak self] _ in
7678 guard let self else { return }
@@ -82,9 +84,6 @@ final class RoutineView: UIView {
8284
8385 grayLine. backgroundColor = BitnagilColor . gray97
8486 grayLine. isHidden = routine. subRoutines. isEmpty
85-
86- subRoutineStackView. axis = . vertical
87- subRoutineStackView. spacing = 10
8887 }
8988
9089 private func configureLayout( ) {
@@ -94,58 +93,53 @@ final class RoutineView: UIView {
9493 [ mainRoutineLabel, mainRoutineCheckButton] . forEach {
9594 mainRoutineView. addSubview ( $0)
9695 }
97- containerView. addSubview ( mainRoutineView)
98- containerView. addSubview ( grayLine)
99- containerView. addSubview ( subRoutineStackView)
96+
97+ [ mainRoutineView, grayLine] . forEach {
98+ routineContentStackView. addArrangedSubview ( $0)
99+ }
100+
101+ for subRoutine in zip ( routine. subRoutines, routine. subRoutineCompleted) {
102+ let subRoutineView = makeSubRoutineView ( subRoutine: subRoutine)
103+ routineContentStackView. addArrangedSubview ( subRoutineView)
104+ }
105+
106+ containerView. addSubview ( routineContentStackView)
100107
101108 timeLabel. snp. makeConstraints { make in
102109 make. top. leading. equalToSuperview ( )
103- make. height . equalTo ( 20 )
110+ make. width . equalTo ( Layout . timeLabelWidth )
104111 }
105112
106113 containerView. snp. makeConstraints { make in
107114 make. top. trailing. bottom. equalToSuperview ( )
108- make. leading. equalTo ( timeLabel. snp. trailing) . offset ( 8 )
115+ make. leading. equalTo ( timeLabel. snp. trailing) . offset ( Layout . containerViewLeadingSpacing)
116+ }
117+
118+ routineContentStackView. snp. makeConstraints { make in
119+ make. leading. equalToSuperview ( ) . offset ( Layout . horizontalMargin)
120+ make. trailing. equalToSuperview ( ) . inset ( Layout . horizontalMargin)
121+ make. top. equalToSuperview ( ) . offset ( Layout . routineContentStackViewVerticalMargin)
122+ make. bottom. equalToSuperview ( ) . inset ( Layout . routineContentStackViewVerticalMargin)
109123 }
110124
111125 mainRoutineView. snp. makeConstraints { make in
112- make. top. equalToSuperview ( ) . offset ( 8 )
113- make. leading. equalToSuperview ( ) . offset ( 16 )
114- make. trailing. equalToSuperview ( ) . inset ( 8 )
115- make. height. equalTo ( 40 )
126+ make. height. greaterThanOrEqualTo ( Layout . mainRoutineViewHeight)
116127 }
117128
118129 mainRoutineLabel. snp. makeConstraints { make in
119130 make. centerY. equalToSuperview ( )
120131 make. leading. equalToSuperview ( )
121- make. width . equalTo ( 211 )
132+ make. trailing . equalTo ( mainRoutineCheckButton . snp . leading ) . offset ( - Layout . mainRoutineLabelTrailingSpacing )
122133 }
123134
124135 mainRoutineCheckButton. snp. makeConstraints { make in
125- make. leading . equalTo ( mainRoutineLabel . snp . trailing ) . offset ( 10 )
126- mainRoutineHeightConstraint = make. height . equalTo ( 40 ) . constraint
127- make. size. equalTo ( 40 )
136+ make. centerY . equalToSuperview ( )
137+ make. trailing . equalToSuperview ( )
138+ make. size. equalTo ( Layout . mainRoutineCheckButtonSize )
128139 }
129140
130141 grayLine. snp. makeConstraints { make in
131- make. top. equalTo ( mainRoutineView. snp. bottom) . offset ( 4 )
132- make. leading. equalToSuperview ( ) . offset ( 16 )
133- make. trailing. equalToSuperview ( ) . inset ( 16 )
134- make. height. equalTo ( 1 )
135- }
136-
137- for subRoutine in zip ( routine. subRoutines, routine. subRoutineCompleted) {
138- let subRoutineView = makeSubRoutineView ( subRoutine: subRoutine)
139- subRoutineView. snp. makeConstraints { make in
140- make. height. equalTo ( 24 )
141- }
142- subRoutineStackView. addArrangedSubview ( subRoutineView)
143- }
144-
145- subRoutineStackView. snp. makeConstraints { make in
146- make. top. equalTo ( grayLine. snp. bottom) . offset ( 10 )
147- make. leading. equalToSuperview ( ) . offset ( 16 )
148- make. trailing. equalToSuperview ( ) . inset ( 16 )
142+ make. height. equalTo ( Layout . grayLineHeight)
149143 }
150144 }
151145
@@ -157,22 +151,28 @@ final class RoutineView: UIView {
157151 subRoutineView. addSubview ( checkButton)
158152 subRoutineView. addSubview ( subRoutineLabel)
159153
160- let checkedIcon = BitnagilIcon . checkedCircleSmallIcon
161- let uncheckedIcon = BitnagilIcon . uncheckedCircleSmallIcon
162- checkButton. setImage ( subRoutine. isDone ? checkedIcon : uncheckedIcon, for: . normal)
163-
164- checkButton. snp. makeConstraints { make in
165- make. top. leading. equalToSuperview ( )
166- make. size. equalTo ( 24 )
167- }
154+ let subRoutineCheckIcon = subRoutine. isDone ? BitnagilIcon . checkedCircleSmallIcon : BitnagilIcon . uncheckedCircleSmallIcon
155+ checkButton. setImage ( subRoutineCheckIcon, for: . normal)
168156
169157 subRoutineLabel. text = subRoutine. title
170158 subRoutineLabel. font = BitnagilFont ( style: . body2, weight: . medium) . font
171159 subRoutineLabel. textColor = BitnagilColor . gray40
160+ subRoutineLabel. numberOfLines = 0
161+
162+ checkButton. snp. makeConstraints { make in
163+ make. leading. equalToSuperview ( )
164+ make. centerY. equalTo ( subRoutineLabel)
165+ make. size. equalTo ( Layout . subRoutineCheckButtonSize)
166+ }
172167
173168 subRoutineLabel. snp. makeConstraints { make in
174- make. leading. equalTo ( checkButton. snp. trailing) . offset ( 10 )
175- make. centerY. equalToSuperview ( )
169+ make. leading. equalTo ( checkButton. snp. trailing) . offset ( Layout . subRoutineLabelLeadingSpacing)
170+ make. trailing. equalToSuperview ( )
171+ make. verticalEdges. equalToSuperview ( )
172+ }
173+
174+ subRoutineView. snp. makeConstraints { make in
175+ make. height. greaterThanOrEqualTo ( Layout . subRoutineViewHeight)
176176 }
177177
178178 return subRoutineView
0 commit comments