From 4afd9612a754a01c07bfe5b5ffc782295b8ee798 Mon Sep 17 00:00:00 2001 From: gme_2 Date: Thu, 27 Sep 2018 16:01:41 +0900 Subject: [PATCH] added view layout --- .../Cell/HomeCollectionTableViewCell.swift | 18 +++++++- .../Home/User Interface/View/Home.storyboard | 43 +++++++++---------- .../View/HomeViewController.swift | 8 ++-- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift b/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift index 79a3c0a1..362db278 100644 --- a/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift +++ b/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift @@ -8,11 +8,10 @@ import UIKit -class HomeCollectionTableViewCell: UITableViewCell { +class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlowLayout { @IBOutlet weak var collectionView: UICollectionView! private var menus: [HomeCollectionModel]? - override func awakeFromNib() { super.awakeFromNib() // Initialization code @@ -58,6 +57,17 @@ class HomeCollectionTableViewCell: UITableViewCell { self.menus = [sendMoneyMenu, mobileRechargeMenu, toadaysRateMenu, trackTransferMenu, transactionStatementMenu, walletToWalletMenu] } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + let itemsPerRow: CGFloat = 2 + let paddingSpace: CGFloat = CGFloat(20 * (itemsPerRow + 1)) + let availableWidth = frame.width - paddingSpace + let widthPerItem = availableWidth / itemsPerRow + + return CGSize(width: widthPerItem, height: widthPerItem) + } + + } @@ -70,6 +80,8 @@ extension HomeCollectionTableViewCell: UICollectionViewDataSource { return menus?.count ?? 0 } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "HomeCollectionCollectionViewCell", for: indexPath) as! HomeCollectionCollectionViewCell cell.model = self.menus?.elementAt(index: indexPath.row) @@ -77,3 +89,5 @@ extension HomeCollectionTableViewCell: UICollectionViewDataSource { return cell } } + + diff --git a/GMERemittance/Module/Home/User Interface/View/Home.storyboard b/GMERemittance/Module/Home/User Interface/View/Home.storyboard index 8937d422..17e49227 100644 --- a/GMERemittance/Module/Home/User Interface/View/Home.storyboard +++ b/GMERemittance/Module/Home/User Interface/View/Home.storyboard @@ -152,43 +152,40 @@ - - + + - + - - + + - - + + - + - + - + - + - - + + - diff --git a/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift b/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift index e637b6b5..7bd070bc 100644 --- a/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift +++ b/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift @@ -8,7 +8,7 @@ import UIKit -class HomeViewController: UIViewController { +class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout { enum Sections: Int { @@ -24,7 +24,7 @@ class HomeViewController: UIViewController { var presenter: HomeModuleInterface? var sections: [Sections] = [.balance, .collection] - + // MARK: VC's Life cycle @@ -99,9 +99,6 @@ extension HomeViewController: UITableViewDelegate { let ramainingBalanceCellHeight: CGFloat = 110 let finalHeight = totalHeight - ramainingBalanceCellHeight return finalHeight -// let width = ((view.frame.width - (insetForCollectionView * 3) ) - 10) / 2 -// let heightForCollectionViewCell = width * (170 / 120) -// return heightForCollectionViewCell * 1.7 } } } @@ -139,3 +136,4 @@ extension HomeViewController: UITableViewDataSource { return cell } } +