From 710637875282f9b0db4d90e0c1c22b83750f270b Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 15 Nov 2022 04:00:54 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20QuestView=EC=99=80=20QuestCell=20?= =?UTF-8?q?=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DailyQuest.xcodeproj/project.pbxproj | 8 + .../Presentation/Common/QuestCell.swift | 168 ++++++++++++++++++ .../Presentation/Common/QuestView.swift | 140 +++++++++++++++ 3 files changed, 316 insertions(+) create mode 100644 DailyQuest/DailyQuest/Presentation/Common/QuestCell.swift create mode 100644 DailyQuest/DailyQuest/Presentation/Common/QuestView.swift diff --git a/DailyQuest/DailyQuest.xcodeproj/project.pbxproj b/DailyQuest/DailyQuest.xcodeproj/project.pbxproj index e85c3d3..7412fad 100644 --- a/DailyQuest/DailyQuest.xcodeproj/project.pbxproj +++ b/DailyQuest/DailyQuest.xcodeproj/project.pbxproj @@ -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 */; }; + 9B1CFB392922AFC700CCE97A /* QuestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B1CFB362922763E00CCE97A /* QuestView.swift */; }; + 9B1CFB3B2922BBDA00CCE97A /* QuestCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B1CFB342922460100CCE97A /* QuestCell.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -59,6 +61,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 = ""; }; + 9B1CFB342922460100CCE97A /* QuestCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestCell.swift; sourceTree = ""; }; + 9B1CFB362922763E00CCE97A /* QuestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -106,6 +110,8 @@ 3449AD5E292219D600B87619 /* Common */ = { isa = PBXGroup; children = ( + 9B1CFB342922460100CCE97A /* QuestCell.swift */, + 9B1CFB362922763E00CCE97A /* QuestView.swift */, ); path = Common; sourceTree = ""; @@ -341,10 +347,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9B1CFB3B2922BBDA00CCE97A /* QuestCell.swift in Sources */, 3449AD5D2922197000B87619 /* User.swift in Sources */, 34ACC32D291DE9C000741371 /* AppDelegate.swift in Sources */, 3449AD5B2922164B00B87619 /* Quest.swift in Sources */, 34ACC32F291DE9C000741371 /* SceneDelegate.swift in Sources */, + 9B1CFB392922AFC700CCE97A /* QuestView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/DailyQuest/DailyQuest/Presentation/Common/QuestCell.swift b/DailyQuest/DailyQuest/Presentation/Common/QuestCell.swift new file mode 100644 index 0000000..cd96ecd --- /dev/null +++ b/DailyQuest/DailyQuest/Presentation/Common/QuestCell.swift @@ -0,0 +1,168 @@ +// +// QuestCell.swift +// DailyQuest +// +// Created by 이다연 on 2022/11/14. +// + +import UIKit +import SnapKit + +class QuestCell: UITableViewCell { + + static let reuseIdentifier = "QuestCell" + + /* + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + */ + + private lazy var userStackView: UIStackView = { + let stackView = UIStackView() + stackView.axis = .horizontal + stackView.alignment = .center + stackView.backgroundColor = .lightGray + stackView.spacing = 10 + stackView.isLayoutMarginsRelativeArrangement = true + stackView.layoutMargins = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) + stackView.layer.cornerRadius = 15 + return stackView + }() + + private lazy var questStackView: UIStackView = { + let stackView = UIStackView() + stackView.axis = .vertical + stackView.backgroundColor = .lightGray + stackView.spacing = 10 + stackView.distribution = .fillEqually + stackView.layer.cornerRadius = 15 + return stackView + }() + + private lazy var userImageView: UIImageView = { + let userImage = UIImageView() + userImage.image = UIImage(systemName: "heart.fill") + userImage.clipsToBounds = true + userImage.backgroundColor = .white + userImage.layer.masksToBounds = true + return userImage + }() + + private lazy var userQuestLabel: UILabel = { + let userQuest = UILabel() + userQuest.frame = CGRect(x: 0, y: 0, width: 60, height: 25) + userQuest.font = UIFont.boldSystemFont(ofSize: 16) + userQuest.text = " " + return userQuest + }() + + + + // MARK: - Methods + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + configureUI() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + userImageView.layer.cornerRadius = userImageView.frame.height / 2 + } + + private func configureUI() { + userStackView.addArrangedSubview(userImageView) + userStackView.addArrangedSubview(userQuestLabel) + questStackView.addArrangedSubview(userStackView) + + addSubview(questStackView) + + userStackView.snp.makeConstraints { make in + make.width.equalTo(questStackView).inset(10) + make.height.equalTo(80) + } + + questStackView.snp.makeConstraints { make in + make.left.equalToSuperview().offset(20) + make.right.equalToSuperview().offset(-20) + } + + + userImageView.snp.makeConstraints { make in + make.height.equalTo(userStackView.snp.height).offset(-50) + make.width.equalTo(userImageView.snp.height) + } + + for subview in questStackView.subviews { + subview.snp.makeConstraints { (make) in + make.height.equalTo(subview.frame.height) + make.width.equalTo(questStackView.snp.width) + } + } + } + + func setup(user: User, quest: [Quest]) { + userQuestLabel.text = user.nickName + "님의 Today Quest" + //guard let image = UIImage(data: user.profile) else { return } + //userImageView.image = image + + let height:Double = 100.0 * (1.0 + Double(quest.count)) + + print(height) + + questStackView.snp.makeConstraints { make in + make.height.equalTo(height) + } + + for q in quest { + var questView = QuestView() + questView.setUp(with: q) + questStackView.addArrangedSubview(questView) + } + + + } +} + +#if canImport(SwiftUI) && DEBUG +import SwiftUI +struct UIViewPreview: UIViewRepresentable { + let view: View + + init(_ builder: @escaping () -> View) { + view = builder() + } + + // MARK: - UIViewRepresentable + + func makeUIView(context: Context) -> UIView { + return view + } + + func updateUIView(_ view: UIView, context: Context) { + view.setContentHuggingPriority(.defaultHigh, for: .horizontal) + view.setContentHuggingPriority(.defaultHigh, for: .vertical) + } +} +#endif + +#if canImport(SwiftUI) && DEBUG +import SwiftUI + +struct QuestCellPreview: PreviewProvider{ + static var previews: some View { + UIViewPreview { + let cell = QuestCell(frame: .zero) + cell.setup(user: User(uuid: UUID(), nickName: "맥스", profile: Data(), backgroundImage: Data(), description: ""), quest: [Quest(title: "물 마시기", startDay: Date(), endDay: Date(), repeat: 0, currentCount: 1, totalCount: 5), Quest(title: "물 마시기", startDay: Date(), endDay: Date(), repeat: 0, currentCount: 1, totalCount: 5), Quest(title: "물 마시기", startDay: Date(), endDay: Date(), repeat: 0, currentCount: 1, totalCount: 5)]) + return cell + } + .previewLayout(.sizeThatFits) + } +} +#endif diff --git a/DailyQuest/DailyQuest/Presentation/Common/QuestView.swift b/DailyQuest/DailyQuest/Presentation/Common/QuestView.swift new file mode 100644 index 0000000..88e0419 --- /dev/null +++ b/DailyQuest/DailyQuest/Presentation/Common/QuestView.swift @@ -0,0 +1,140 @@ +// +// QuestView.swift +// DailyQuest +// +// Created by 이다연 on 2022/11/14. +// + +import UIKit +import SnapKit + +class QuestView: UIView { + + // assets 에 한번에 나중에 추가하려고 일단은 임의로 색상 넣음 + private var backgroundLabel: UILabel = { + let label = UILabel() + label.frame = CGRect(x: 0, y: 0, width: 300, height: 80) + label.backgroundColor = .yellow + label.layer.masksToBounds = true + return label + }() + + private var progressLabel: UILabel = { + let label = UILabel() + label.frame = CGRect(x: 0, y: 0, width: 0, height: 80) + label.backgroundColor = .systemYellow + label.layer.masksToBounds = true + return label + }() + + private var questLabel: UILabel = { + let label = UILabel() + label.frame = CGRect(x: 0, y: 0, width: 60, height: 25) + label.textAlignment = .center + label.text = "" + label.font = UIFont.boldSystemFont(ofSize: 16) + label.sizeToFit() + return label + }() + + private var countLabel: UILabel = { + let label = UILabel() + label.frame = CGRect(x: 0, y: 0, width: 60, height: 25) + label.textAlignment = .center + label.text = "" + label.font = UIFont.boldSystemFont(ofSize: 16) + label.sizeToFit() + return label + }() + + override init(frame: CGRect) { + super.init(frame: frame) + configureUI() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + backgroundLabel.layer.cornerRadius = backgroundLabel.bounds.size.height / 7 + progressLabel.layer.cornerRadius = progressLabel.bounds.size.height / 8 + } + + private func configureUI() { + self.addSubview(backgroundLabel) + self.addSubview(progressLabel) + self.addSubview(questLabel) + self.addSubview(countLabel) + + backgroundLabel.snp.makeConstraints { make in + make.height.equalTo(80) + make.width.equalTo(300) + } + + progressLabel.snp.makeConstraints { make in + make.height.equalTo(80) + make.leading.equalTo(backgroundLabel) + } + + questLabel.snp.makeConstraints { make in + make.top.equalTo(backgroundLabel).inset(30) + make.left.equalTo(backgroundLabel).inset(10) + } + + countLabel.snp.makeConstraints { make in + make.top.equalTo(backgroundLabel).inset(30) + make.right.equalTo(backgroundLabel).inset(10) + } + + } + + func setUp(with quest: Quest) { + let progressWidth = 300.0 * (Double(quest.currentCount)/Double(quest.totalCount)) + + questLabel.text = quest.title + countLabel.text = String(quest.currentCount) + " / " + String(quest.totalCount) + progressLabel.snp.makeConstraints { make in + make.width.equalTo(progressWidth) + } + } +} +/* +#if canImport(SwiftUI) && DEBUG +import SwiftUI +struct UIViewPreview: UIViewRepresentable { + let view: View + + init(_ builder: @escaping () -> View) { + view = builder() + } + + // MARK: - UIViewRepresentable + + func makeUIView(context: Context) -> UIView { + return view + } + + func updateUIView(_ view: UIView, context: Context) { + view.setContentHuggingPriority(.defaultHigh, for: .horizontal) + view.setContentHuggingPriority(.defaultHigh, for: .vertical) + } +} +#endif + +#if canImport(SwiftUI) && DEBUG +import SwiftUI + +struct QuestionViewPreview: PreviewProvider{ + static var previews: some View { + UIViewPreview { + let view = QuestView(frame: .zero) + view.setUp(with: Quest(title: "물 마시기", startDay: Date(), endDay: Date(), repeat: 0, currentCount: 2, totalCount: 5)) + return view + }.previewLayout((.fixed(width: 300, height: 80))) + } +} +#endif + +*/