Skip to content

Commit f50fbc1

Browse files
committed
[Feat] Team-Sopetit#9 - 세그먼트컨트롤 추가
1 parent 3f84553 commit f50fbc1

File tree

3 files changed

+112
-6
lines changed

3 files changed

+112
-6
lines changed

iOS-Practice/iOS-Practice/RoutineView.swift

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,30 @@ import SnapKit
1212
final class RoutineView: UIView {
1313

1414
// 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+
}
1622

1723
// 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
2139
}()
2240

2341
let collectionView: UICollectionView = {
@@ -37,6 +55,9 @@ final class RoutineView: UIView {
3755
setLayout()
3856
setAddTarget()
3957
setRegisterCell()
58+
self.segmentedControl.addTarget(self, action: #selector(didChangeValue(segment:)), for: .valueChanged)
59+
self.segmentedControl.selectedSegmentIndex = 0
60+
self.didChangeValue(segment: self.segmentedControl)
4061
}
4162

4263
@available(*, unavailable)
@@ -54,12 +75,21 @@ extension RoutineView {
5475
}
5576

5677
func setHierarchy() {
57-
self.addSubviews(collectionView)
78+
self.addSubviews(collectionView, segmentedControl, secondView)
5879
}
5980

6081
func setLayout() {
82+
segmentedControl.snp.makeConstraints() {
83+
$0.leading.trailing.top.equalToSuperview()
84+
$0.height.equalTo(38)
85+
}
6186
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)
6393
}
6494
}
6595

@@ -79,4 +109,8 @@ extension RoutineView {
79109
func setDataBind() {
80110

81111
}
112+
113+
@objc private func didChangeValue(segment: UISegmentedControl) {
114+
self.shouldHideFirstView = segment.selectedSegmentIndex != 0
115+
}
82116
}

iOS-Practice/iOS-Practice/RoutineViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ final class RoutineViewController: UIViewController {
1818
private let routineView = RoutineView()
1919
private lazy var collectionview = routineView.collectionView
2020

21+
22+
2123
// MARK: - Life Cycles
2224

2325
override func loadView() {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// TopViewView.swift
3+
// iOS-Practice
4+
//
5+
// Created by Woo Jye Lee on 1/6/24.
6+
//
7+
8+
import UIKit
9+
10+
import SnapKit
11+
12+
final class TopViewView: UIView {
13+
14+
// MARK: - Properties
15+
16+
17+
// MARK: - UI Components
18+
19+
20+
// MARK: - Life Cycles
21+
22+
override init(frame: CGRect) {
23+
super.init(frame: frame)
24+
25+
setUI()
26+
setHierarchy()
27+
setLayout()
28+
setAddTarget()
29+
setRegisterCell()
30+
}
31+
32+
@available(*, unavailable)
33+
required init?(coder: NSCoder) {
34+
fatalError("init(coder:) has not been implemented")
35+
}
36+
}
37+
38+
// MARK: - Extensions
39+
40+
extension TopViewView {
41+
42+
func setUI() {
43+
44+
}
45+
46+
func setHierarchy() {
47+
48+
}
49+
50+
func setLayout() {
51+
52+
}
53+
54+
func setAddTarget() {
55+
56+
}
57+
58+
@objc
59+
func buttonTapped() {
60+
61+
}
62+
63+
func setRegisterCell() {
64+
65+
}
66+
67+
func setDataBind() {
68+
69+
}
70+
}

0 commit comments

Comments
 (0)