diff --git a/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift b/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift index aebf1d1..3703077 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift @@ -19,8 +19,7 @@ final class HomeCollectionReusableView: UICollectionReusableView { // MARK: - UI Components - private lazy var dateFormatter = DateFormatter() - private var dateLabel = UILabel() + var dateLabel = UILabel() private let dateView = UIView() private var motivationLabel = UILabel() private var graphicImageView = UIImageView() @@ -42,15 +41,10 @@ final class HomeCollectionReusableView: UICollectionReusableView { extension HomeCollectionReusableView { private func setUI() { backgroundColor = .nottodoWhite - dateFormatter.do { - $0.locale = Locale(identifier: "ko_KR") - $0.dateFormat = "YYYY년 M월" - $0.timeZone = TimeZone(identifier: "KST") - } dateLabel.do { $0.textColor = .nottodoBlack $0.font = .PretendardBold(size: 18.adjusted) - $0.text = "2023년 1월" // dateFormatter로 수정 +// $0.text = "2023년 1월" // dateFormatter로 수정 } dateView.backgroundColor = .yellow_basic motivationLabel.do { diff --git a/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift b/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift index 885620a..4951851 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift @@ -19,7 +19,9 @@ final class HomeViewController: UIViewController { var banner: BannerResponseDTO? var missionId: Int? private var clickedDay: String? - private let dateFormatter = DateFormatter() + private let todayDateFormatter = DateFormatter() + private let mothlyDateFormatter = DateFormatter() + private var currentPage: Date? = Date() // MARK: - UI Components @@ -44,7 +46,7 @@ final class HomeViewController: UIViewController { super.viewWillAppear(animated) requestBannerAPI() requestWeeklyMissoinAPI(startDate: "2023-01-23") - requestDailyMissionAPI(date: "2023-01-25") + requestDailyMissionAPI(date: clickedDay ?? "") } } @@ -73,10 +75,15 @@ extension HomeViewController: UICollectionViewDelegate { for: .valueChanged) } - dateFormatter.do { + todayDateFormatter.do { $0.locale = Locale(identifier: "ko_KR") $0.dateFormat = "yyyy-MM-dd" } + + mothlyDateFormatter.do { + $0.locale = Locale(identifier: "ko_KR") + $0.dateFormat = "yyyy년 M월" + } } private func setAddTarget() { @@ -152,7 +159,7 @@ extension HomeViewController: UICollectionViewDelegate { @objc func handleRefreshControl() { // 컨텐츠를 업데이트하세요. requestBannerAPI() - requestDailyMissionAPI(date: "2023-01-25") + requestDailyMissionAPI(date: clickedDay ?? "") homeView.homeCollectionView.reloadData() DispatchQueue.main.async { @@ -171,6 +178,7 @@ extension HomeViewController: UICollectionViewDataSource { case 0: guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeCalendarCollectionViewCell.identifier, for: indexPath) as? HomeCalendarCollectionViewCell else { return UICollectionViewCell() } cell.calendar.delegate = self + self.currentPage = cell.calendar.currentPage return cell default: if missionList.isEmpty { @@ -233,6 +241,7 @@ extension HomeViewController: UICollectionViewDataSource { withReuseIdentifier: HomeCollectionReusableView.identifier, for: indexPath ) as? HomeCollectionReusableView else { return UICollectionReusableView() } + header.dateLabel.text = mothlyDateFormatter.string(from: self.currentPage ?? Date()) if let banner = banner { header.setRandomData(banner: banner) } @@ -284,7 +293,7 @@ extension HomeViewController: UICollectionViewDelegateFlowLayout { extension HomeViewController: FSCalendarDelegate { func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) { - clickedDay = dateFormatter.string(from: date) + clickedDay = todayDateFormatter.string(from: date) requestDailyMissionAPI(date: clickedDay ?? "") } } diff --git a/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift b/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift index 48ed7a1..cae9bf3 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift @@ -1,6 +1,5 @@ import UIKit -import FSCalendar import SnapKit import Then @@ -9,7 +8,6 @@ final class HomeView: UIView { // MARK: - UI Components lazy var homeCollectionView = UICollectionView(frame: .zero, collectionViewLayout: layout()) - var calendar = FSCalendar(frame: .zero) let addMissionButton = NotTodoButton(frame: CGRect(), mode: .withImage, text: I18N.addMissoinButton, image: .plus, font: .semiBold, size: 16) // MARK: - Life Cycle