Skip to content

Commit

Permalink
[FEAT] HomView CollectionView구조로 재구현 연습 #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ffalswo2 committed Jul 6, 2022
1 parent 4402b59 commit a20ccf0
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 124 deletions.
4 changes: 4 additions & 0 deletions HousLab_iOS/HousLab_iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
B59C945D2874962D005865CA /* RulesTodoCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59C945C2874962D005865CA /* RulesTodoCollectionViewCell.swift */; };
B59C945F28749DFC005865CA /* HeaderCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59C945E28749DFC005865CA /* HeaderCollectionReusableView.swift */; };
B59C94612874C7AF005865CA /* ComingEventsCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59C94602874C7AF005865CA /* ComingEventsCollectionViewCell.swift */; };
B59C9465287586AA005865CA /* PopUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59C9464287586AA005865CA /* PopUpViewController.swift */; };
B5B5C11D2872E3DB00FC5134 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = B5B5C11C2872E3DB00FC5134 /* SnapKit */; };
B5B5C1202872E43E00FC5134 /* Then in Frameworks */ = {isa = PBXBuildFile; productRef = B5B5C11F2872E43E00FC5134 /* Then */; };
B5B5C1222872E63C00FC5134 /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B5C1212872E63C00FC5134 /* HomeViewController.swift */; };
Expand Down Expand Up @@ -54,6 +55,7 @@
B59C945C2874962D005865CA /* RulesTodoCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RulesTodoCollectionViewCell.swift; sourceTree = "<group>"; };
B59C945E28749DFC005865CA /* HeaderCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderCollectionReusableView.swift; sourceTree = "<group>"; };
B59C94602874C7AF005865CA /* ComingEventsCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComingEventsCollectionViewCell.swift; sourceTree = "<group>"; };
B59C9464287586AA005865CA /* PopUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopUpViewController.swift; sourceTree = "<group>"; };
B5B5C1212872E63C00FC5134 /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
B5B5C1242872E7A000FC5134 /* UIFont+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Extension.swift"; sourceTree = "<group>"; };
B5B5C1262872E7BC00FC5134 /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -203,6 +205,7 @@
B5B5C1212872E63C00FC5134 /* HomeViewController.swift */,
B59C94542874274F005865CA /* RulesTodosView.swift */,
B59C945E28749DFC005865CA /* HeaderCollectionReusableView.swift */,
B59C9464287586AA005865CA /* PopUpViewController.swift */,
);
path = MinJae;
sourceTree = "<group>";
Expand Down Expand Up @@ -337,6 +340,7 @@
B85302AA28728F6300F06234 /* ViewController.swift in Sources */,
B85302C72872A20600F06234 /* JiHyeonViewController.swift in Sources */,
B5B5C12F2872E85200FC5134 /* UIButton+Extension.swift in Sources */,
B59C9465287586AA005865CA /* PopUpViewController.swift in Sources */,
B5B5C1352872E89F00FC5134 /* NSObject+Extension.swift in Sources */,
B59C94612874C7AF005865CA /* ComingEventsCollectionViewCell.swift in Sources */,
B85302C12872A1EC00F06234 /* HoseViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import UIKit

protocol ComingEventsCollectionViewCellDelegate: AnyObject {
func showPopup(_ row: Int)
}


class ComingEventsCollectionViewCell: UICollectionViewCell {

private enum Size {
Expand All @@ -15,6 +20,8 @@ class ComingEventsCollectionViewCell: UICollectionViewCell {
static let eventCellSize = CGSize(width: 88, height: 88)
}

weak var delegate: ComingEventsCollectionViewCellDelegate?

private let subtitleLabel = UILabel().then {
$0.text = "Coming up-"
$0.font = .systemFont(ofSize: 20, weight: .semibold)
Expand Down Expand Up @@ -44,13 +51,14 @@ class ComingEventsCollectionViewCell: UICollectionViewCell {

subtitleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(5)
make.leading.equalToSuperview().offset(24)
make.leading.equalToSuperview().inset(24)
}

incomingEventsCollectionView.snp.makeConstraints { make in
make.top.equalTo(subtitleLabel.snp.bottom).offset(12)
make.leading.trailing.equalToSuperview()
make.bottom.equalToSuperview().inset(24)
make.leading.equalToSuperview().inset(24)
make.bottom.equalToSuperview()
make.trailing.equalToSuperview()
}
}

Expand All @@ -66,14 +74,14 @@ class ComingEventsCollectionViewCell: UICollectionViewCell {

extension ComingEventsCollectionViewCell: UICollectionViewDelegate {

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
delegate?.showPopup(indexPath.row)
}

}

extension ComingEventsCollectionViewCell: UICollectionViewDataSource {

// func numberOfSections(in collectionView: UICollectionView) -> Int {
// return 1
// }


func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return EventDataModel.sampleData.count + 1
}
Expand Down Expand Up @@ -112,7 +120,7 @@ extension ComingEventsCollectionViewCell: UICollectionViewDelegateFlowLayout {
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 5, left: 0, bottom: 0, right: 0)
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class RulesTodoCollectionViewCell: UICollectionViewCell {

private lazy var ruleLabelStackView = UIStackView(arrangedSubviews: [ruleLabel1, ruleLabel2, ruleLabel3, ruleLabel4, ruleLabel5]).then {
$0.axis = .vertical
$0.alignment = .center
$0.alignment = .leading
$0.distribution = .fillEqually
$0.spacing = 8
}

private let ruleBackground = UIView()

private lazy var ruleStackView = UIStackView(arrangedSubviews: [ruleTitleLabel, ruleLabelStackView]).then {
$0.axis = .vertical
$0.spacing = 12
Expand All @@ -53,9 +55,11 @@ class RulesTodoCollectionViewCell: UICollectionViewCell {

private let todoLabel5 = RulesTodosView()

private let todoBackground = UIView()

private lazy var todoLabelStackView = UIStackView(arrangedSubviews: [todoLabel1, todoLabel2, todoLabel3, todoLabel4, todoLabel5]).then {
$0.axis = .vertical
$0.alignment = .center
$0.alignment = .leading
$0.distribution = .fillEqually
$0.spacing = 8
}
Expand All @@ -76,17 +80,59 @@ class RulesTodoCollectionViewCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
render()
configUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func render() {
addSubview(totalStackView)
totalStackView.snp.makeConstraints { make in
make.top.bottom.leading.trailing.equalToSuperview()
addSubViews([ruleTitleLabel,ruleBackground, todoTitleLabel, todoBackground])
ruleBackground.addSubview(ruleLabelStackView)
todoBackground.addSubview(todoLabelStackView)

ruleTitleLabel.snp.makeConstraints { make in
make.top.equalToSuperview()
make.leading.equalToSuperview().offset(24)
}

ruleBackground.snp.makeConstraints { make in
make.top.equalTo(ruleTitleLabel.snp.bottom).offset(12)
make.leading.equalTo(ruleTitleLabel.snp.leading)
make.bottom.equalToSuperview()
make.width.equalTo(156)
}

ruleLabelStackView.snp.makeConstraints { make in
make.center.equalToSuperview()
}

todoTitleLabel.snp.makeConstraints { make in
make.centerY.equalTo(ruleTitleLabel)
make.leading.equalTo(ruleBackground.snp.trailing).offset(15)
}

todoBackground.snp.makeConstraints { make in
make.top.equalTo(todoTitleLabel.snp.bottom).offset(12)
make.leading.equalTo(todoTitleLabel.snp.leading)
make.bottom.equalToSuperview()
make.trailing.equalToSuperview().inset(24)
make.width.equalTo(156)
}

todoLabelStackView.snp.makeConstraints { make in
make.center.equalToSuperview()
}

}

private func configUI() {
ruleBackground.backgroundColor = UIColor(hex: "EFF5FF")
todoBackground.backgroundColor = UIColor(hex: "EFF5FF")

ruleBackground.layer.cornerRadius = 16
todoBackground.layer.cornerRadius = 16
}

func setRulesData(_ data: [RulesDataModel]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import UIKit

class HeaderCollectionReusableView: UICollectionReusableView {

static let identifier = "HeaderCollectionReusableView"

let subtitleLabel = UILabel().then {
$0.text = "Coming up-"
$0.font = .systemFont(ofSize: 20, weight: .semibold)
Expand Down
Loading

0 comments on commit a20ccf0

Please sign in to comment.