diff --git a/DailyQuest/DailyQuest.xcodeproj/project.pbxproj b/DailyQuest/DailyQuest.xcodeproj/project.pbxproj index def25fb..53f42a4 100644 --- a/DailyQuest/DailyQuest.xcodeproj/project.pbxproj +++ b/DailyQuest/DailyQuest.xcodeproj/project.pbxproj @@ -26,6 +26,8 @@ 34ACC364291DEF6100741371 /* FirebaseFirestore in Frameworks */ = {isa = PBXBuildFile; productRef = 34ACC363291DEF6100741371 /* FirebaseFirestore */; }; 34ACC366291DEF6100741371 /* FirebaseStorage in Frameworks */ = {isa = PBXBuildFile; productRef = 34ACC365291DEF6100741371 /* FirebaseStorage */; }; 34ACC36C291DF0DD00741371 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 34ACC36B291DF0DD00741371 /* GoogleService-Info.plist */; }; + B50078D629222F3F0070AFC4 /* CircleCheckView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50078D529222F3F0070AFC4 /* CircleCheckView.swift */; }; + B58DFC0A29227DA800C68A4B /* CalendarCellCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58DFC0929227DA800C68A4B /* CalendarCellCollectionViewCell.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -61,6 +63,8 @@ 34ACC34D291DE9C100741371 /* DailyQuestUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyQuestUITests.swift; sourceTree = ""; }; 34ACC34F291DE9C100741371 /* DailyQuestUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyQuestUITestsLaunchTests.swift; sourceTree = ""; }; 34ACC36B291DF0DD00741371 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + B50078D529222F3F0070AFC4 /* CircleCheckView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleCheckView.swift; sourceTree = ""; }; + B58DFC0929227DA800C68A4B /* CalendarCellCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarCellCollectionViewCell.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -108,6 +112,8 @@ 3449AD5E292219D600B87619 /* Common */ = { isa = PBXGroup; children = ( + B50078D529222F3F0070AFC4 /* CircleCheckView.swift */, + B58DFC0929227DA800C68A4B /* CalendarCellCollectionViewCell.swift */, 3449AD5F29222B3900B87619 /* UserInfoCell.swift */, ); path = Common; @@ -345,6 +351,8 @@ buildActionMask = 2147483647; files = ( 3449AD5D2922197000B87619 /* User.swift in Sources */, + B50078D629222F3F0070AFC4 /* CircleCheckView.swift in Sources */, + B58DFC0A29227DA800C68A4B /* CalendarCellCollectionViewCell.swift in Sources */, 34ACC32D291DE9C000741371 /* AppDelegate.swift in Sources */, 3449AD5B2922164B00B87619 /* Quest.swift in Sources */, 3449AD6029222B3900B87619 /* UserInfoCell.swift in Sources */, diff --git a/DailyQuest/DailyQuest/Presentation/Common/CalendarCellCollectionViewCell.swift b/DailyQuest/DailyQuest/Presentation/Common/CalendarCellCollectionViewCell.swift new file mode 100644 index 0000000..13851ad --- /dev/null +++ b/DailyQuest/DailyQuest/Presentation/Common/CalendarCellCollectionViewCell.swift @@ -0,0 +1,68 @@ +// +// CalendarCellCollectionViewCell.swift +// DailyQuest +// +// Created by wickedRun on 2022/11/14. +// + +import UIKit +import SnapKit + +class CalendarCell: UICollectionViewCell { + + // MARK: - Sub Views + + private lazy var circleCheckView: CircleCheckView = { + let view = CircleCheckView() + return view + }() + + private lazy var dayLabel: UILabel = { + let view = UILabel() + view.textAlignment = .center + view.textColor = .gray + view.adjustsFontSizeToFitWidth = true + return view + }() + + override init(frame: CGRect) { + super.init(frame: frame) + + addSubviews() + setupContstraints() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Configuration View + + private func addSubviews() { + self.contentView.addSubview(circleCheckView) + self.contentView.addSubview(dayLabel) + } + + private func setupContstraints() { + circleCheckView.snp.makeConstraints { make in + make.top.horizontalEdges.equalToSuperview() + make.height.equalTo(circleCheckView.snp.width) + } + + dayLabel.snp.makeConstraints { make in + make.top.equalTo(circleCheckView.snp.bottom).offset(4) + make.bottom.horizontalEdges.equalToSuperview() + } + } + + // MARK: - Methods + + /// CalendarCell의 UI를 변경하는 메소드 + /// - parameters: + /// - state : CircleCheckView.State + /// - day : Int + func configure(state: CircleCheckView.State, day: Int) { + dayLabel.text = "\(day)" + circleCheckView.updateState(state) + } +} diff --git a/DailyQuest/DailyQuest/Presentation/Common/CircleCheckView.swift b/DailyQuest/DailyQuest/Presentation/Common/CircleCheckView.swift new file mode 100644 index 0000000..14c204b --- /dev/null +++ b/DailyQuest/DailyQuest/Presentation/Common/CircleCheckView.swift @@ -0,0 +1,114 @@ +// +// CircleCheckView.swift +// DailyQuest +// +// Created by wickedRun on 2022/11/14. +// + +import UIKit +import SnapKit + +class CircleCheckView: UIView { + + // MARK: - Sub Views + + private lazy var circleBackground: UIView = { + let view = UIView() + view.backgroundColor = UIColor(red: 0.973, green: 0.953, blue: 0.831, alpha: 1) + return view + }() + + private lazy var displayLabel: UILabel = { + let label = UILabel() + label.textAlignment = .center + label.adjustsFontSizeToFitWidth = true + label.textColor = .white + return label + }() + + override init(frame: CGRect = .zero) { + super.init(frame: frame) + + self.clipsToBounds = true + + addSubviews() + setupConstraints() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + self.layer.cornerRadius = self.bounds.height / 2 + } + + // MARK: - Configuration View + + private func addSubviews() { + self.addSubview(circleBackground) + circleBackground.addSubview(displayLabel) + } + + private func setupConstraints() { + circleBackground.snp.makeConstraints { make in + make.edges.equalToSuperview() + } + + displayLabel.snp.makeConstraints { make in + make.top.bottom.equalToSuperview() + make.centerX.equalToSuperview() + } + } + + // MARK: - Methods + + private func setDone() { + displayLabel.text = "✓" + displayLabel.font = .systemFont(ofSize: self.displayLabel.font.pointSize, weight: .bold) + displayLabel.textColor = .white + circleBackground.backgroundColor = UIColor(red: 1, green: 0.871, blue: 0.49, alpha: 1) + } + + private func setNumber(to number: Int) { + let range = (0...9) + + if range ~= number { + self.displayLabel.text = "\(number)" + } else { + self.displayLabel.text = "9+" + } + + displayLabel.font = .boldSystemFont(ofSize: self.displayLabel.font.pointSize) + displayLabel.textColor = UIColor(red: 0.365, green: 0.114, blue: 0.235, alpha: 1) + circleBackground.backgroundColor = UIColor(red: 0.973, green: 0.953, blue: 0.831, alpha: 1) + } + + /// Self.State의 케이스로 해당 뷰를 업데이트 하는 메소드 + /// - parameters: + /// - state: CircleCheckView.State + func updateState(_ state: CircleCheckView.State) { + switch state { + case .display(let number): + setNumber(to: number) + case .done: + setDone() + } + } +} + +// MARK: - Nested Enum - CircleCheckView.State + +extension CircleCheckView { + + /// CircleCheckView.State 타입 + /// + /// Case: + /// - done + /// - display(number: Int) + enum State { + case done + case display(number: Int) + } +}