-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
DailyQuest/DailyQuest/Presentation/Common/CalendarCellCollectionViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
115
DailyQuest/DailyQuest/Presentation/Common/CircleCheckView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+" | ||
} | ||
|
||
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) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9를 초과하면 +로 표기해주는 센스 굳입니다.