@@ -12,12 +12,30 @@ import SnapKit
12
12
final class RoutineView : UIView {
13
13
14
14
// MARK: - Properties
15
-
15
+ var shouldHideFirstView : Bool ? { // 상단 세그먼트컨트롤 터치를 감지하는 프로퍼티
16
+ didSet {
17
+ guard let shouldHideFirstView = self . shouldHideFirstView else { return }
18
+ self . collectionView. isHidden = shouldHideFirstView
19
+ self . secondView. isHidden = !self . collectionView. isHidden
20
+ }
21
+ }
16
22
17
23
// MARK: - UI Components
18
- let topView : UIView = {
19
- let view = UIView ( )
20
- return view
24
+ let segmentedControl : UISegmentedControl = {
25
+ let control = UISegmentedControl ( items: [ " 데일리 루틴 " , " 행복 루틴 " ] )
26
+ control. translatesAutoresizingMaskIntoConstraints = false
27
+ control. backgroundColor = . white
28
+ let titleTextAttributes = [ NSAttributedString . Key. foregroundColor: UIColor . black]
29
+ control. setTitleTextAttributes ( titleTextAttributes, for: . normal)
30
+ let titleTextAttributes2 = [ NSAttributedString . Key. foregroundColor: UIColor . red]
31
+ control. setTitleTextAttributes ( titleTextAttributes2, for: . selected)
32
+ return control
33
+ } ( )
34
+
35
+ let secondView : UIView = { // 행복 루틴 페이지
36
+ let view = UIView ( )
37
+ view. translatesAutoresizingMaskIntoConstraints = false
38
+ return view
21
39
} ( )
22
40
23
41
let collectionView : UICollectionView = {
@@ -37,6 +55,9 @@ final class RoutineView: UIView {
37
55
setLayout ( )
38
56
setAddTarget ( )
39
57
setRegisterCell ( )
58
+ self . segmentedControl. addTarget ( self , action: #selector( didChangeValue ( segment: ) ) , for: . valueChanged)
59
+ self . segmentedControl. selectedSegmentIndex = 0
60
+ self . didChangeValue ( segment: self . segmentedControl)
40
61
}
41
62
42
63
@available ( * , unavailable)
@@ -54,12 +75,21 @@ extension RoutineView {
54
75
}
55
76
56
77
func setHierarchy( ) {
57
- self . addSubviews ( collectionView)
78
+ self . addSubviews ( collectionView, segmentedControl , secondView )
58
79
}
59
80
60
81
func setLayout( ) {
82
+ segmentedControl. snp. makeConstraints ( ) {
83
+ $0. leading. trailing. top. equalToSuperview ( )
84
+ $0. height. equalTo ( 38 )
85
+ }
61
86
collectionView. snp. makeConstraints {
62
- $0. edges. equalToSuperview ( )
87
+ $0. leading. trailing. bottom. equalToSuperview ( ) // 여기서 가리키는 superView는?
88
+ $0. top. equalTo ( segmentedControl. snp. bottom)
89
+ }
90
+ secondView. snp. makeConstraints ( ) {
91
+ $0. leading. trailing. bottom. equalToSuperview ( )
92
+ $0. top. equalTo ( segmentedControl. snp. bottom)
63
93
}
64
94
}
65
95
@@ -79,4 +109,8 @@ extension RoutineView {
79
109
func setDataBind( ) {
80
110
81
111
}
112
+
113
+ @objc private func didChangeValue( segment: UISegmentedControl ) {
114
+ self . shouldHideFirstView = segment. selectedSegmentIndex != 0
115
+ }
82
116
}
0 commit comments