From fe7cb4bf37b1f70f8cf4100a25282d75081f08b5 Mon Sep 17 00:00:00 2001 From: Hansangjin98 Date: Sun, 23 May 2021 03:24:12 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EB=A9=94=EC=9D=B8=20=EB=B7=B0=20?= =?UTF-8?q?=EB=8D=B0=EB=AA=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SOPKATHON_Kick.xcodeproj/project.pbxproj | 64 ++++- SOPKATHON_Kick/Common/Extension/UIColor.swift | 26 ++ .../Home/Cell/HomeCollectionViewCell.swift | 15 ++ .../Sources/Home/Cell/HomeTableViewCell.swift | 29 +++ SOPKATHON_Kick/Sources/Home/Home.storyboard | 226 +++++++++++++++++- .../Sources/Home/HomeViewController.swift | 92 ++++++- .../Home/{ => MainTabBar}/Main.storyboard | 0 .../MainTabBarController.swift | 0 .../Home/Model/HomeCollectionViewModel.swift | 34 +++ .../Home/Model/HomeTableViewModel.swift | 31 +++ 10 files changed, 503 insertions(+), 14 deletions(-) create mode 100644 SOPKATHON_Kick/Common/Extension/UIColor.swift create mode 100644 SOPKATHON_Kick/Sources/Home/Cell/HomeCollectionViewCell.swift create mode 100644 SOPKATHON_Kick/Sources/Home/Cell/HomeTableViewCell.swift rename SOPKATHON_Kick/Sources/Home/{ => MainTabBar}/Main.storyboard (100%) rename SOPKATHON_Kick/Sources/Home/{ => MainTabBar}/MainTabBarController.swift (100%) create mode 100644 SOPKATHON_Kick/Sources/Home/Model/HomeCollectionViewModel.swift create mode 100644 SOPKATHON_Kick/Sources/Home/Model/HomeTableViewModel.swift diff --git a/SOPKATHON_Kick.xcodeproj/project.pbxproj b/SOPKATHON_Kick.xcodeproj/project.pbxproj index 49612f9..41d7fab 100644 --- a/SOPKATHON_Kick.xcodeproj/project.pbxproj +++ b/SOPKATHON_Kick.xcodeproj/project.pbxproj @@ -23,6 +23,11 @@ 4039178E265947D200BF2C6F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 403917712659434900BF2C6F /* Main.storyboard */; }; 4058242726593B5B00845A48 /* Login.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4058242626593B5B00845A48 /* Login.storyboard */; }; 4058242B26593BAB00845A48 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4058242A26593BAB00845A48 /* LoginViewController.swift */; }; + 40F598E22659568F005DD065 /* HomeCollectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598E12659568F005DD065 /* HomeCollectionViewModel.swift */; }; + 40F598E926595E86005DD065 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598E826595E86005DD065 /* UIColor.swift */; }; + 40F598EF26596594005DD065 /* HomeTableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598EE26596594005DD065 /* HomeTableViewModel.swift */; }; + 40F598F326596C59005DD065 /* HomeCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598F226596C59005DD065 /* HomeCollectionViewCell.swift */; }; + 40F598F626596D7B005DD065 /* HomeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F598F526596D7B005DD065 /* HomeTableViewCell.swift */; }; 5601F4C72F3894872F74A14A /* Pods_SOPKATHON_Kick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49F03FBAA0C8B548BCAF5943 /* Pods_SOPKATHON_Kick.framework */; }; /* End PBXBuildFile section */ @@ -45,6 +50,11 @@ 403917862659462100BF2C6F /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = ""; }; 4058242626593B5B00845A48 /* Login.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Login.storyboard; sourceTree = ""; }; 4058242A26593BAB00845A48 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = ""; }; + 40F598E12659568F005DD065 /* HomeCollectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeCollectionViewModel.swift; sourceTree = ""; }; + 40F598E826595E86005DD065 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = ""; }; + 40F598EE26596594005DD065 /* HomeTableViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTableViewModel.swift; sourceTree = ""; }; + 40F598F226596C59005DD065 /* HomeCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeCollectionViewCell.swift; sourceTree = ""; }; + 40F598F526596D7B005DD065 /* HomeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTableViewCell.swift; sourceTree = ""; }; 49F03FBAA0C8B548BCAF5943 /* Pods_SOPKATHON_Kick.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SOPKATHON_Kick.framework; sourceTree = BUILT_PRODUCTS_DIR; }; FA81244F86E24D2DAFA2C3D9 /* Pods-SOPKATHON_Kick.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SOPKATHON_Kick.release.xcconfig"; path = "Target Support Files/Pods-SOPKATHON_Kick/Pods-SOPKATHON_Kick.release.xcconfig"; sourceTree = ""; }; FF8A74EE6ADFCE2FEB2CB831 /* Pods-SOPKATHON_Kick.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SOPKATHON_Kick.debug.xcconfig"; path = "Target Support Files/Pods-SOPKATHON_Kick/Pods-SOPKATHON_Kick.debug.xcconfig"; sourceTree = ""; }; @@ -83,6 +93,7 @@ 400CFA08265932CF0080CB1B /* SOPKATHON_Kick */ = { isa = PBXGroup; children = ( + 40F598E626595E65005DD065 /* Common */, 4058241F26593AA600845A48 /* Sources */, 4058241E26593A8A00845A48 /* Resources */, 4058241D265939C700845A48 /* Application */, @@ -134,10 +145,11 @@ 4058242126593AD600845A48 /* Home */ = { isa = PBXGroup; children = ( + 40F598E426595926005DD065 /* Cell */, + 40F598E026595673005DD065 /* Model */, + 40F598DF265954D7005DD065 /* MainTabBar */, 403917692659416F00BF2C6F /* HomeViewController.swift */, 4039176D265941B000BF2C6F /* Home.storyboard */, - 403917712659434900BF2C6F /* Main.storyboard */, - 403917862659462100BF2C6F /* MainTabBarController.swift */, ); path = Home; sourceTree = ""; @@ -176,6 +188,49 @@ path = Detail; sourceTree = ""; }; + 40F598DF265954D7005DD065 /* MainTabBar */ = { + isa = PBXGroup; + children = ( + 403917712659434900BF2C6F /* Main.storyboard */, + 403917862659462100BF2C6F /* MainTabBarController.swift */, + ); + path = MainTabBar; + sourceTree = ""; + }; + 40F598E026595673005DD065 /* Model */ = { + isa = PBXGroup; + children = ( + 40F598E12659568F005DD065 /* HomeCollectionViewModel.swift */, + 40F598EE26596594005DD065 /* HomeTableViewModel.swift */, + ); + path = Model; + sourceTree = ""; + }; + 40F598E426595926005DD065 /* Cell */ = { + isa = PBXGroup; + children = ( + 40F598F226596C59005DD065 /* HomeCollectionViewCell.swift */, + 40F598F526596D7B005DD065 /* HomeTableViewCell.swift */, + ); + path = Cell; + sourceTree = ""; + }; + 40F598E626595E65005DD065 /* Common */ = { + isa = PBXGroup; + children = ( + 40F598E726595E6C005DD065 /* Extension */, + ); + path = Common; + sourceTree = ""; + }; + 40F598E726595E6C005DD065 /* Extension */ = { + isa = PBXGroup; + children = ( + 40F598E826595E86005DD065 /* UIColor.swift */, + ); + path = Extension; + sourceTree = ""; + }; 7476745A01D2EAECE836D67A /* Pods */ = { isa = PBXGroup; children = ( @@ -314,12 +369,17 @@ files = ( 403917752659447300BF2C6F /* WritingViewController.swift in Sources */, 4058242B26593BAB00845A48 /* LoginViewController.swift in Sources */, + 40F598F626596D7B005DD065 /* HomeTableViewCell.swift in Sources */, 403917872659462100BF2C6F /* MainTabBarController.swift in Sources */, + 40F598EF26596594005DD065 /* HomeTableViewModel.swift in Sources */, 403917812659450A00BF2C6F /* MyPageViewController.swift in Sources */, 400CFA0A265932CF0080CB1B /* AppDelegate.swift in Sources */, + 40F598E22659568F005DD065 /* HomeCollectionViewModel.swift in Sources */, 400CFA0C265932CF0080CB1B /* SceneDelegate.swift in Sources */, 4039176A2659416F00BF2C6F /* HomeViewController.swift in Sources */, 4039177E265944D500BF2C6F /* KingViewController.swift in Sources */, + 40F598E926595E86005DD065 /* UIColor.swift in Sources */, + 40F598F326596C59005DD065 /* HomeCollectionViewCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/SOPKATHON_Kick/Common/Extension/UIColor.swift b/SOPKATHON_Kick/Common/Extension/UIColor.swift new file mode 100644 index 0000000..3b196c9 --- /dev/null +++ b/SOPKATHON_Kick/Common/Extension/UIColor.swift @@ -0,0 +1,26 @@ +// +// UIColor.swift +// SOPKATHON_Kick +// +// Created by 한상진 on 2021/05/23. +// + +import Foundation +import UIKit + +extension UIColor { + + // MARK: hex 변환 가능 init + convenience init(hex: UInt, alpha: CGFloat = 1.0) { + self.init( + red: CGFloat((hex & 0xFF0000) >> 16) / 255.0, + green: CGFloat((hex & 0x00FF00) >> 8) / 255.0, + blue: CGFloat(hex & 0x0000FF) / 255.0, + alpha: CGFloat(alpha) + ) + } + + class var main_Color: UIColor { UIColor(hex: 0xFF6C6C) } + + +} diff --git a/SOPKATHON_Kick/Sources/Home/Cell/HomeCollectionViewCell.swift b/SOPKATHON_Kick/Sources/Home/Cell/HomeCollectionViewCell.swift new file mode 100644 index 0000000..bb37f0c --- /dev/null +++ b/SOPKATHON_Kick/Sources/Home/Cell/HomeCollectionViewCell.swift @@ -0,0 +1,15 @@ +// +// HomeCollectionViewCell.swift +// SOPKATHON_Kick +// +// Created by 한상진 on 2021/05/23. +// + +import UIKit + +class HomeCollectionViewCell: UICollectionViewCell { + + @IBOutlet weak var image: UIImageView! + @IBOutlet weak var title: UILabel! + @IBOutlet weak var content: UILabel! +} diff --git a/SOPKATHON_Kick/Sources/Home/Cell/HomeTableViewCell.swift b/SOPKATHON_Kick/Sources/Home/Cell/HomeTableViewCell.swift new file mode 100644 index 0000000..83e61ef --- /dev/null +++ b/SOPKATHON_Kick/Sources/Home/Cell/HomeTableViewCell.swift @@ -0,0 +1,29 @@ +// +// HomeTableViewCell.swift +// SOPKATHON_Kick +// +// Created by 한상진 on 2021/05/23. +// + +import UIKit + +class HomeTableViewCell: UITableViewCell { + + @IBOutlet weak var title: UILabel! + @IBOutlet weak var content: UILabel! + @IBOutlet weak var clickAndTime: UILabel! + @IBOutlet weak var like: UILabel! + + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + +} diff --git a/SOPKATHON_Kick/Sources/Home/Home.storyboard b/SOPKATHON_Kick/Sources/Home/Home.storyboard index 35e39e8..a866632 100644 --- a/SOPKATHON_Kick/Sources/Home/Home.storyboard +++ b/SOPKATHON_Kick/Sources/Home/Home.storyboard @@ -6,6 +6,7 @@ + @@ -14,15 +15,236 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/SOPKATHON_Kick/Sources/Home/HomeViewController.swift b/SOPKATHON_Kick/Sources/Home/HomeViewController.swift index a2d5c2c..92febf0 100644 --- a/SOPKATHON_Kick/Sources/Home/HomeViewController.swift +++ b/SOPKATHON_Kick/Sources/Home/HomeViewController.swift @@ -9,22 +9,94 @@ import UIKit class HomeViewController: UIViewController { + @IBOutlet weak var topView: UIView! + @IBOutlet weak var scrollViewHeightConstraint: NSLayoutConstraint! + @IBOutlet weak var homeCollectionView: UICollectionView! + @IBOutlet weak var homeTableView: UITableView! + @IBOutlet weak var homePageControl: UIPageControl! + var homeCollectionViewList: [HomeCollectionViewModel] = [] + var homeTableViewList: [HomeTableViewModel] = [] + + override func viewDidLoad() { super.viewDidLoad() - - print("33") - // Do any additional setup after loading the view. + topView.backgroundColor = .main_Color + delegateSet() + homeTableViewSet() + homeCollectionViewSet() + setScrollHeight() + } + + func homeTableViewSet() { + homeTableViewList.append(contentsOf: [ + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302), + HomeTableViewModel(title: "테스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트", click: 32, minute: 15, like: 302) + + ]) + } + + func delegateSet() { + homeTableView.delegate = self + homeTableView.dataSource = self + homeCollectionView.delegate = self + homeCollectionView.dataSource = self + } + + func homeCollectionViewSet() { + homeCollectionViewList.append(contentsOf: [ + HomeCollectionViewModel(imageName: "", title: "테ㅔㅔ스트", contents: "테ㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔㅔ테스트") + ]) } + func setScrollHeight() + { + scrollViewHeightConstraint.constant = CGFloat(homeTableViewList.count * 59) + homeTableView.reloadData() + } - /* - // MARK: - Navigation +} - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. +extension HomeViewController: UICollectionViewDelegate, UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return homeCollectionViewList.count } - */ + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? HomeCollectionViewCell else { return UICollectionViewCell() } + cell.image.image = homeCollectionViewList[indexPath.row].image + cell.title.text = homeCollectionViewList[indexPath.row].title + cell.content.text = homeCollectionViewList[indexPath.row].contents + + return cell + + } +} + +extension HomeViewController: UITableViewDelegate, UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + + return homeTableViewList.count + } + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 91 + } + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? HomeTableViewCell else { return UITableViewCell() } + cell.title.text = homeTableViewList[indexPath.row].title + cell.content.text = homeTableViewList[indexPath.row].contents + cell.clickAndTime.text = "조회 " + "\(homeTableViewList[indexPath.row].click)" + "•" + "\(homeTableViewList[indexPath.row].minute)" + " 전" + cell.like.text = "\(homeTableViewList[indexPath.row].like)" + return cell + } } diff --git a/SOPKATHON_Kick/Sources/Home/Main.storyboard b/SOPKATHON_Kick/Sources/Home/MainTabBar/Main.storyboard similarity index 100% rename from SOPKATHON_Kick/Sources/Home/Main.storyboard rename to SOPKATHON_Kick/Sources/Home/MainTabBar/Main.storyboard diff --git a/SOPKATHON_Kick/Sources/Home/MainTabBarController.swift b/SOPKATHON_Kick/Sources/Home/MainTabBar/MainTabBarController.swift similarity index 100% rename from SOPKATHON_Kick/Sources/Home/MainTabBarController.swift rename to SOPKATHON_Kick/Sources/Home/MainTabBar/MainTabBarController.swift diff --git a/SOPKATHON_Kick/Sources/Home/Model/HomeCollectionViewModel.swift b/SOPKATHON_Kick/Sources/Home/Model/HomeCollectionViewModel.swift new file mode 100644 index 0000000..e1d950d --- /dev/null +++ b/SOPKATHON_Kick/Sources/Home/Model/HomeCollectionViewModel.swift @@ -0,0 +1,34 @@ +// +// HomeCollectionViewModel.swift +// SOPKATHON_Kick +// +// Created by 한상진 on 2021/05/23. +// + +import Foundation +import UIKit + +struct HomeCollectionViewModel { + let image: UIImage + let title: String + let contents: String + + + init(imageName : String, + title: String, + contents: String) { + + + self.title = title + self.contents = contents + + if let image = UIImage(named: imageName) + { + self.image = image + } + else + { + self.image = UIImage() + } + } +} diff --git a/SOPKATHON_Kick/Sources/Home/Model/HomeTableViewModel.swift b/SOPKATHON_Kick/Sources/Home/Model/HomeTableViewModel.swift new file mode 100644 index 0000000..47a805d --- /dev/null +++ b/SOPKATHON_Kick/Sources/Home/Model/HomeTableViewModel.swift @@ -0,0 +1,31 @@ +// +// HomeTableViewModel.swift +// SOPKATHON_Kick +// +// Created by 한상진 on 2021/05/23. +// + +import Foundation +import UIKit + +struct HomeTableViewModel { + let title: String + let contents: String + let click: Int + let minute: Int + let like: Int + + + init(title: String, + contents: String, + click: Int, + minute: Int, + like: Int) { + + self.title = title + self.contents = contents + self.click = click + self.minute = minute + self.like = like + } +}