Created
May 30, 2019 20:09
-
-
Save amixpal/e442090d293637b24989db6842207ae7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TemporaryViewController.swift | |
// Fitme | |
// | |
// Created by Paly on 5/29/19. | |
// Copyright © 2019 Paly. All rights reserved. | |
// | |
import UIKit | |
import RappleProgressHUD | |
class TemporaryViewController: UIViewController { | |
@IBOutlet weak var mainView: UIView! | |
@IBOutlet weak var itemCollectionView: UICollectionView! | |
private var headerView : DashboardHeaderViewCollectionViewCell? | |
private var footerView: DashboardBottomViewCollectionViewCell? | |
var estimateWidth = 160.0 | |
var cellMarginSize = 16.0 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setUpGridView() | |
initUI() | |
self.mainView.layer.shadowColor = UIColor.lightGray.cgColor | |
self.mainView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0) | |
self.mainView.layer.shadowRadius = 1 | |
self.mainView.layer.shadowOpacity = 0.1 | |
} | |
func initUI() { | |
self.itemCollectionView.delegate = self | |
self.itemCollectionView.dataSource = self | |
self.itemCollectionView.register(UINib(nibName: nibParameter.DASHBOARD_CENTER_NIB, bundle: nil), forCellWithReuseIdentifier: nibParameter.DASHBOARD_CENTER_NIB) | |
self.itemCollectionView.register(UINib(nibName: "DashboardHeaderViewCollectionViewCell", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "DashboardHeaderViewCollectionViewCell") | |
itemCollectionView.register(DashboardBottomViewCollectionViewCell.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "DashboardBottomViewCollectionViewCell") | |
DispatchQueue.main.async{self.itemCollectionView.reloadData()} | |
self.itemCollectionView.isHidden = false | |
} | |
func setUpGridView(){ | |
let flow = itemCollectionView?.collectionViewLayout as! UICollectionViewFlowLayout | |
flow.minimumInteritemSpacing = CGFloat(self.cellMarginSize) | |
flow.minimumLineSpacing = CGFloat(self.cellMarginSize) | |
} | |
} | |
extension TemporaryViewController: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { | |
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { | |
switch kind { | |
case UICollectionView.elementKindSectionHeader: | |
let headerView = itemCollectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "DashboardHeaderViewCollectionViewCell", for: indexPath) as! DashboardHeaderViewCollectionViewCell | |
self.headerView = headerView | |
self.headerView?.contentView?.clipsToBounds = true | |
self.headerView?.dashBoardHeaderCollectionViewDelegate = self | |
self.headerView?.clipsToBounds = true | |
self.headerView?.initUI() | |
return headerView | |
case UICollectionView.elementKindSectionFooter: | |
let headerView = itemCollectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "DashboardBottomViewCollectionViewCell", for: indexPath) as! DashboardBottomViewCollectionViewCell | |
self.footerView = headerView | |
self.headerView?.contentView?.clipsToBounds = true | |
footerView?.dashboardBottomDelegate = self | |
footerView?.clipsToBounds = true | |
return footerView! | |
default: | |
return headerView! | |
} | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { | |
return CGSize(width: collectionView.frame.width, height: 300.0) | |
} | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return 3 | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
let width = -10 + (collectionView.frame.width) | |
return CGSize(width: width, | |
height: 90) | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = itemCollectionView.dequeueReusableCell(withReuseIdentifier: nibParameter.DASHBOARD_CENTER_NIB, for: indexPath) as! DashboardPastTrainingCollectionViewCell | |
cell.imageView.sd_setShowActivityIndicatorView(true) | |
cell.imageView.sd_setIndicatorStyle(.gray) | |
cell.firstLabel.text = "training.trainingName" | |
cell.imageView.sd_setImage(with: URL(string: "training.trainingImage" != nil ? "training.trainingImage" ?? "" : ""), placeholderImage: UIImage.init(named: "tour_placeholder"), options: .handleCookies, completed: nil) | |
// cell.layer.borderColor = UIColor.white.cgColor | |
return cell | |
} | |
} | |
extension TemporaryViewController: DashboardHeaderViewCollectionViewDelegate { | |
func handleView() { | |
} | |
} | |
extension TemporaryViewController: DashboardBottomViewCollectionViewDelegate { | |
func didSelect(tem atIndex: Int) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment