From f6bc80b1e215dac7c7d3f931a09b848a4b550042 Mon Sep 17 00:00:00 2001 From: sanghee Date: Sun, 12 Jun 2022 01:53:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8B=AC=EB=A0=A5=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=20=EC=9A=94=EC=9D=BC=20(weekdayCollectionViewCell)=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(ios-h/airbnb#32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Calendar/CalendarViewController.swift | 39 ++++++++++++++++++- .../View/CalendarCollectionViewCell.swift | 5 +++ .../ViewModel/CalendarViewModel.swift | 2 + .../WeekdayCollectionViewDataSource.swift | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/iOS/airbnb/Present/Main/Calendar/CalendarViewController.swift b/iOS/airbnb/Present/Main/Calendar/CalendarViewController.swift index 3ceb0af3f..45d672fbd 100644 --- a/iOS/airbnb/Present/Main/Calendar/CalendarViewController.swift +++ b/iOS/airbnb/Present/Main/Calendar/CalendarViewController.swift @@ -16,16 +16,51 @@ final class CalendarViewController: UIViewController { private var weekdayListCollectionView: UICollectionView! = nil private var calendarCollectionView: UICollectionView! = nil + private var weekdayCollectionViewDataSource = WeekdayCollectionViewDataSource() + override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white - self.navigationItem.title = "숙소 찾기" - + configureCollectionView() + configureDataSource() + configure() bind() } private func bind() { +// viewModel + } + + private func configure() { + self.navigationItem.title = "숙소 찾기" + + view.addSubview(weekdayListCollectionView) + + weekdayListCollectionView.snp.makeConstraints { + $0.leading.trailing.top.equalTo(view.safeAreaLayoutGuide) + $0.height.equalTo(90) + } + } + + private func configureCollectionView() { + let flowLayout = UICollectionViewFlowLayout() + flowLayout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) + flowLayout.minimumLineSpacing = 10 + flowLayout.itemSize = CGSize(width: view.bounds.width / 9, height: view.bounds.width / 9) + + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout) + collectionView.translatesAutoresizingMaskIntoConstraints = false + collectionView.isScrollEnabled = false + collectionView.clipsToBounds = true + collectionView.showsVerticalScrollIndicator = false + collectionView.register(CalendarCollectionViewCell.self, + forCellWithReuseIdentifier: String(describing: CalendarCollectionViewCell.self)) + weekdayListCollectionView = collectionView + } + + private func configureDataSource() { + weekdayListCollectionView.dataSource = weekdayCollectionViewDataSource } } diff --git a/iOS/airbnb/Present/Main/Calendar/View/CalendarCollectionViewCell.swift b/iOS/airbnb/Present/Main/Calendar/View/CalendarCollectionViewCell.swift index 7fee4c302..89b178a20 100644 --- a/iOS/airbnb/Present/Main/Calendar/View/CalendarCollectionViewCell.swift +++ b/iOS/airbnb/Present/Main/Calendar/View/CalendarCollectionViewCell.swift @@ -28,6 +28,7 @@ final class CalendarCollectionViewCell: UICollectionViewCell { contentView.backgroundColor = .white contentView.addSubview(textLabel) +// addSubview(containerView) setConstraints() } @@ -36,6 +37,10 @@ final class CalendarCollectionViewCell: UICollectionViewCell { $0.edges.equalTo(self.safeAreaLayoutGuide) } +// containerView.snp.makeConstraints { +// $0.edges.equalTo(contentView.safeAreaLayoutGuide) +// } + textLabel.snp.makeConstraints { $0.center.equalTo(self.contentView) } diff --git a/iOS/airbnb/Present/Main/Calendar/ViewModel/CalendarViewModel.swift b/iOS/airbnb/Present/Main/Calendar/ViewModel/CalendarViewModel.swift index 01b5753bc..795d29484 100644 --- a/iOS/airbnb/Present/Main/Calendar/ViewModel/CalendarViewModel.swift +++ b/iOS/airbnb/Present/Main/Calendar/ViewModel/CalendarViewModel.swift @@ -17,4 +17,6 @@ final class CalendarViewModel { let totalDates = [String]() // dates를 담는 배열 let daysCountInMonth = 0 // 해당 월이 며칠까지 있는지 let weekdayStarting = 0 // 시작일 + + } diff --git a/iOS/airbnb/Present/Main/Calendar/WeekdayCollectionViewDataSource.swift b/iOS/airbnb/Present/Main/Calendar/WeekdayCollectionViewDataSource.swift index fc1302616..85b61f582 100644 --- a/iOS/airbnb/Present/Main/Calendar/WeekdayCollectionViewDataSource.swift +++ b/iOS/airbnb/Present/Main/Calendar/WeekdayCollectionViewDataSource.swift @@ -10,7 +10,7 @@ import UIKit final class WeekdayCollectionViewDataSource: NSObject, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 7 + return CalendarViewModel.weeks.count } func collectionView(_ collectionView: UICollectionView,