Skip to content

Commit

Permalink
[Feat] Team-Sopetit#9 - 세그먼트컨트롤 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
leewoojye committed Jan 6, 2024
1 parent 3f84553 commit f50fbc1
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 6 deletions.
46 changes: 40 additions & 6 deletions iOS-Practice/iOS-Practice/RoutineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,30 @@ import SnapKit
final class RoutineView: UIView {

// MARK: - Properties

var shouldHideFirstView: Bool? { // 상단 세그먼트컨트롤 터치를 감지하는 프로퍼티
didSet {
guard let shouldHideFirstView = self.shouldHideFirstView else { return }
self.collectionView.isHidden = shouldHideFirstView
self.secondView.isHidden = !self.collectionView.isHidden
}
}

// MARK: - UI Components
let topView: UIView = {
let view = UIView()
return view
let segmentedControl: UISegmentedControl = {
let control = UISegmentedControl(items: ["데일리 루틴", "행복 루틴"])
control.translatesAutoresizingMaskIntoConstraints = false
control.backgroundColor = .white
let titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
control.setTitleTextAttributes(titleTextAttributes, for: .normal)
let titleTextAttributes2 = [NSAttributedString.Key.foregroundColor: UIColor.red]
control.setTitleTextAttributes(titleTextAttributes2, for: .selected)
return control
}()

let secondView: UIView = { // 행복 루틴 페이지
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

let collectionView: UICollectionView = {
Expand All @@ -37,6 +55,9 @@ final class RoutineView: UIView {
setLayout()
setAddTarget()
setRegisterCell()
self.segmentedControl.addTarget(self, action: #selector(didChangeValue(segment:)), for: .valueChanged)
self.segmentedControl.selectedSegmentIndex = 0
self.didChangeValue(segment: self.segmentedControl)
}

@available(*, unavailable)
Expand All @@ -54,12 +75,21 @@ extension RoutineView {
}

func setHierarchy() {
self.addSubviews(collectionView)
self.addSubviews(collectionView, segmentedControl, secondView)
}

func setLayout() {
segmentedControl.snp.makeConstraints() {
$0.leading.trailing.top.equalToSuperview()
$0.height.equalTo(38)
}
collectionView.snp.makeConstraints {
$0.edges.equalToSuperview()
$0.leading.trailing.bottom.equalToSuperview() // 여기서 가리키는 superView는?
$0.top.equalTo(segmentedControl.snp.bottom)
}
secondView.snp.makeConstraints() {
$0.leading.trailing.bottom.equalToSuperview()
$0.top.equalTo(segmentedControl.snp.bottom)
}
}

Expand All @@ -79,4 +109,8 @@ extension RoutineView {
func setDataBind() {

}

@objc private func didChangeValue(segment: UISegmentedControl) {
self.shouldHideFirstView = segment.selectedSegmentIndex != 0
}
}
2 changes: 2 additions & 0 deletions iOS-Practice/iOS-Practice/RoutineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ final class RoutineViewController: UIViewController {
private let routineView = RoutineView()
private lazy var collectionview = routineView.collectionView



// MARK: - Life Cycles

override func loadView() {
Expand Down
70 changes: 70 additions & 0 deletions iOS-Practice/iOS-Practice/TopViewView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// TopViewView.swift
// iOS-Practice
//
// Created by Woo Jye Lee on 1/6/24.
//

import UIKit

import SnapKit

final class TopViewView: UIView {

// MARK: - Properties


// MARK: - UI Components


// MARK: - Life Cycles

override init(frame: CGRect) {
super.init(frame: frame)

setUI()
setHierarchy()
setLayout()
setAddTarget()
setRegisterCell()
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

// MARK: - Extensions

extension TopViewView {

func setUI() {

}

func setHierarchy() {

}

func setLayout() {

}

func setAddTarget() {

}

@objc
func buttonTapped() {

}

func setRegisterCell() {

}

func setDataBind() {

}
}

0 comments on commit f50fbc1

Please sign in to comment.