Skip to content

Commit

Permalink
Merge pull request #9 from boostcampwm-2022/feature/QuestCell
Browse files Browse the repository at this point in the history
QuestView와 QuestCell 완성
  • Loading branch information
jinwoong16 committed Nov 15, 2022
2 parents e1c6705 + 4cdbd20 commit 90002f9
Show file tree
Hide file tree
Showing 3 changed files with 316 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DailyQuest/DailyQuest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
9B1CFB392922AFC700CCE97A /* QuestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B1CFB362922763E00CCE97A /* QuestView.swift */; };
9B1CFB3B2922BBDA00CCE97A /* QuestCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B1CFB342922460100CCE97A /* QuestCell.swift */; };
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 */
Expand Down Expand Up @@ -63,6 +65,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>"; };
9B1CFB342922460100CCE97A /* QuestCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestCell.swift; sourceTree = "<group>"; };
9B1CFB362922763E00CCE97A /* QuestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestView.swift; 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 */
Expand Down Expand Up @@ -112,6 +116,8 @@
3449AD5E292219D600B87619 /* Common */ = {
isa = PBXGroup;
children = (
9B1CFB342922460100CCE97A /* QuestCell.swift */,
9B1CFB362922763E00CCE97A /* QuestView.swift */,
B50078D529222F3F0070AFC4 /* CircleCheckView.swift */,
B58DFC0929227DA800C68A4B /* CalendarCellCollectionViewCell.swift */,
3449AD5F29222B3900B87619 /* UserInfoCell.swift */,
Expand Down Expand Up @@ -350,13 +356,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9B1CFB3B2922BBDA00CCE97A /* QuestCell.swift in Sources */,
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 */,
34ACC32F291DE9C000741371 /* SceneDelegate.swift in Sources */,
9B1CFB392922AFC700CCE97A /* QuestView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
168 changes: 168 additions & 0 deletions DailyQuest/DailyQuest/Presentation/Common/QuestCell.swift
Original file line number Diff line number Diff line change
@@ -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<View: UIView>: 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
140 changes: 140 additions & 0 deletions DailyQuest/DailyQuest/Presentation/Common/QuestView.swift
Original file line number Diff line number Diff line change
@@ -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<View: UIView>: 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
*/

0 comments on commit 90002f9

Please sign in to comment.