Skip to content

Commit

Permalink
[FEAT] CollectionView 이슈
Browse files Browse the repository at this point in the history
- 컬렉션 뷰안에 컬렉션 뷰
  • Loading branch information
ffalswo2 committed Jul 6, 2022
1 parent e8808f2 commit 4402b59
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 229 deletions.
32 changes: 30 additions & 2 deletions HousLab_iOS/HousLab_iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
B59C94552874274F005865CA /* RulesTodosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59C94542874274F005865CA /* RulesTodosView.swift */; };
B59C945928744DAE005865CA /* ProfileDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59C945828744DAE005865CA /* ProfileDataModel.swift */; };
B59C945B28744ED5005865CA /* ProfileCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59C945A28744ED5005865CA /* ProfileCollectionViewCell.swift */; };
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 */; };
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 @@ -48,6 +51,9 @@
B59C94542874274F005865CA /* RulesTodosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RulesTodosView.swift; sourceTree = "<group>"; };
B59C945828744DAE005865CA /* ProfileDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileDataModel.swift; sourceTree = "<group>"; };
B59C945A28744ED5005865CA /* ProfileCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileCollectionViewCell.swift; sourceTree = "<group>"; };
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>"; };
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 @@ -91,6 +97,23 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
B59C94622874C7BE005865CA /* Events */ = {
isa = PBXGroup;
children = (
B59C94602874C7AF005865CA /* ComingEventsCollectionViewCell.swift */,
B5B5C1412872F3C300FC5134 /* EventsCollectionViewCell.swift */,
);
path = Events;
sourceTree = "<group>";
};
B59C94632874CA89005865CA /* Profile */ = {
isa = PBXGroup;
children = (
B59C945A28744ED5005865CA /* ProfileCollectionViewCell.swift */,
);
path = Profile;
sourceTree = "<group>";
};
B5B5C1232872E75D00FC5134 /* Extensions */ = {
isa = PBXGroup;
children = (
Expand All @@ -115,8 +138,9 @@
B5B5C1402872F3AB00FC5134 /* Cells */ = {
isa = PBXGroup;
children = (
B5B5C1412872F3C300FC5134 /* EventsCollectionViewCell.swift */,
B59C945A28744ED5005865CA /* ProfileCollectionViewCell.swift */,
B59C94632874CA89005865CA /* Profile */,
B59C94622874C7BE005865CA /* Events */,
B59C945C2874962D005865CA /* RulesTodoCollectionViewCell.swift */,
);
path = Cells;
sourceTree = "<group>";
Expand Down Expand Up @@ -178,6 +202,7 @@
B5B5C1232872E75D00FC5134 /* Extensions */,
B5B5C1212872E63C00FC5134 /* HomeViewController.swift */,
B59C94542874274F005865CA /* RulesTodosView.swift */,
B59C945E28749DFC005865CA /* HeaderCollectionReusableView.swift */,
);
path = MinJae;
sourceTree = "<group>";
Expand Down Expand Up @@ -308,10 +333,12 @@
B59C945928744DAE005865CA /* ProfileDataModel.swift in Sources */,
B5B5C1392872E8FA00FC5134 /* UICollectionView+Extension.swift in Sources */,
B59C945328742440005865CA /* TodoDataModels.swift in Sources */,
B59C945F28749DFC005865CA /* HeaderCollectionReusableView.swift in Sources */,
B85302AA28728F6300F06234 /* ViewController.swift in Sources */,
B85302C72872A20600F06234 /* JiHyeonViewController.swift in Sources */,
B5B5C12F2872E85200FC5134 /* UIButton+Extension.swift in Sources */,
B5B5C1352872E89F00FC5134 /* NSObject+Extension.swift in Sources */,
B59C94612874C7AF005865CA /* ComingEventsCollectionViewCell.swift in Sources */,
B85302C12872A1EC00F06234 /* HoseViewController.swift in Sources */,
B5B5C13B2872E91E00FC5134 /* UIStackView+Extension.swift in Sources */,
B5B5C1312872E86600FC5134 /* UIViewController+Extension.swift in Sources */,
Expand All @@ -332,6 +359,7 @@
B5B5C1422872F3C300FC5134 /* EventsCollectionViewCell.swift in Sources */,
B59C9451287423BD005865CA /* RulesDataModel.swift in Sources */,
B5B5C1292872E7FC00FC5134 /* UIView+Extension.swift in Sources */,
B59C945D2874962D005865CA /* RulesTodoCollectionViewCell.swift in Sources */,
B85302A828728F6300F06234 /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// ComingEventsCollectionViewCell.swift
// HousLab_iOS
//
// Created by 김민재 on 2022/07/06.
//

import UIKit

class ComingEventsCollectionViewCell: UICollectionViewCell {

private enum Size {
static let screenWidth = UIScreen.main.bounds.width
static let addEventCellSize = CGSize(width: 72, height: 88)
static let eventCellSize = CGSize(width: 88, height: 88)
}

private let subtitleLabel = UILabel().then {
$0.text = "Coming up-"
$0.font = .systemFont(ofSize: 20, weight: .semibold)
$0.textAlignment = .left
}

private var incomingEventsCollectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewLayout()).then {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
$0.collectionViewLayout = layout
$0.showsHorizontalScrollIndicator = false
}

override init(frame: CGRect) {
super.init(frame: frame)
render()
setEventCollectionView()
}

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

private func render() {
addSubview(incomingEventsCollectionView)
addSubview(subtitleLabel)

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

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

private func setEventCollectionView() {
incomingEventsCollectionView.register(cell: EventsCollectionViewCell.self)

incomingEventsCollectionView.delegate = self
incomingEventsCollectionView.dataSource = self
}

}


extension ComingEventsCollectionViewCell: UICollectionViewDelegate {

}

extension ComingEventsCollectionViewCell: UICollectionViewDataSource {

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

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return EventDataModel.sampleData.count + 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = incomingEventsCollectionView.dequeueReusableCell(withReuseIdentifier: EventsCollectionViewCell.className, for: indexPath) as? EventsCollectionViewCell else { return UICollectionViewCell() }

if indexPath.row == 0 {
cell.d_dayLabel.isHidden = true
cell.addIcon.isHidden = false
cell.backgroudImageView.image = nil
cell.backgroundColor = UIColor(hex: "FFF8E6")
return cell
} else {
cell.d_dayLabel.isHidden = false
cell.addIcon.isHidden = true
cell.backgroudImageView.image = UIImage(systemName: "clock")
cell.backgroundColor = UIColor(hex: "FFDE8A")
}

cell.setEventCellData(EventDataModel.sampleData[indexPath.row - 1])
return cell
}


}


extension ComingEventsCollectionViewCell: UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.row == 0 {
return Size.addEventCellSize
}
return Size.eventCellSize
}

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

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 8
}

}
121 changes: 121 additions & 0 deletions HousLab_iOS/HousLab_iOS/MinJae/Cells/RulesTodoCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// RulesTodoCollectionViewCell.swift
// HousLab_iOS
//
// Created by 김민재 on 2022/07/06.
//

import UIKit

class RulesTodoCollectionViewCell: UICollectionViewCell {

private let ruleTitleLabel = UILabel().then {
$0.text = "Rules"
$0.font = .systemFont(ofSize: 20, weight: .semibold)
$0.textAlignment = .left
}

private let ruleLabel1 = RulesTodosView()

private let ruleLabel2 = RulesTodosView()

private let ruleLabel3 = RulesTodosView()

private let ruleLabel4 = RulesTodosView()

private let ruleLabel5 = RulesTodosView()

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

private lazy var ruleStackView = UIStackView(arrangedSubviews: [ruleTitleLabel, ruleLabelStackView]).then {
$0.axis = .vertical
$0.spacing = 12
}

private let todoTitleLabel = UILabel().then {
$0.text = "To-Do"
$0.font = .systemFont(ofSize: 20, weight: .semibold)
$0.textAlignment = .left
}

private let todoLabel1 = RulesTodosView()

private let todoLabel2 = RulesTodosView()

private let todoLabel3 = RulesTodosView()

private let todoLabel4 = RulesTodosView()

private let todoLabel5 = RulesTodosView()

private lazy var todoLabelStackView = UIStackView(arrangedSubviews: [todoLabel1, todoLabel2, todoLabel3, todoLabel4, todoLabel5]).then {
$0.axis = .vertical
$0.alignment = .center
$0.distribution = .fillEqually
$0.spacing = 8
}

private lazy var todoStackView = UIStackView(arrangedSubviews: [todoTitleLabel, todoLabelStackView]).then {
$0.axis = .vertical
$0.spacing = 12
}

private lazy var totalStackView = UIStackView(arrangedSubviews: [ruleStackView, todoStackView]).then {
$0.axis = .horizontal
$0.distribution = .fillEqually
$0.spacing = 15
}



override init(frame: CGRect) {
super.init(frame: frame)
render()
}

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

func setRulesData(_ data: [RulesDataModel]) {

let labelList = [ruleLabel1, ruleLabel2, ruleLabel3, ruleLabel4, ruleLabel5]

var index = 0
labelList.forEach {
$0.checkButton.isHidden = true
$0.setRulesLabelData(rule: data[index].ruleString)

index += 1
}

}

func setTodosData(_ data: [TodoDataModel]) {

let labelList = [todoLabel1, todoLabel2, todoLabel3, todoLabel4, todoLabel5]

var index = 0
labelList.forEach {
$0.circleImageView.isHidden = true
$0.setRulesLabelData(rule: data[index].todoString)

index += 1
}

}


}
38 changes: 38 additions & 0 deletions HousLab_iOS/HousLab_iOS/MinJae/HeaderCollectionReusableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// CollectionReusableView.swift
// HousLab_iOS
//
// Created by 김민재 on 2022/07/06.
//

import UIKit

class HeaderCollectionReusableView: UICollectionReusableView {

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

override init(frame: CGRect) {
super.init(frame: frame)
render()
}

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

private func render() {
addSubview(subtitleLabel)
subtitleLabel.snp.makeConstraints { make in
make.top.leading.trailing.bottom.equalToSuperview()
}
}

func setSubTitleLabel(data: String) {
subtitleLabel.text = data
}

}
Loading

0 comments on commit 4402b59

Please sign in to comment.