Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CalendarCell 구현 #8

Merged
merged 4 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions DailyQuest/DailyQuest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 */
Expand Down Expand Up @@ -59,6 +61,8 @@
34ACC34D291DE9C100741371 /* DailyQuestUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyQuestUITests.swift; sourceTree = "<group>"; };
34ACC34F291DE9C100741371 /* DailyQuestUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyQuestUITestsLaunchTests.swift; sourceTree = "<group>"; };
34ACC36B291DF0DD00741371 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
B50078D529222F3F0070AFC4 /* CircleCheckView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleCheckView.swift; sourceTree = "<group>"; };
B58DFC0929227DA800C68A4B /* CalendarCellCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarCellCollectionViewCell.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -106,6 +110,8 @@
3449AD5E292219D600B87619 /* Common */ = {
isa = PBXGroup;
children = (
B50078D529222F3F0070AFC4 /* CircleCheckView.swift */,
B58DFC0929227DA800C68A4B /* CalendarCellCollectionViewCell.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -342,6 +348,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 */,
34ACC32F291DE9C000741371 /* SceneDelegate.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
115 changes: 115 additions & 0 deletions DailyQuest/DailyQuest/Presentation/Common/CircleCheckView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// 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)
view.clipsToBounds = true
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+"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}
}