Skip to content

Instantly share code, notes, and snippets.

@bangiqi
Created January 22, 2018 14:09
Show Gist options
  • Save bangiqi/5f9098f06af5004733b1f9e41c963a7c to your computer and use it in GitHub Desktop.
Save bangiqi/5f9098f06af5004733b1f9e41c963a7c to your computer and use it in GitHub Desktop.
//
// ViewedViewController.swift
// Pasar Selon
//
// Created by Rizki Ramdani on 1/14/18.
// Copyright © 2018 Rizki Ramdani. All rights reserved.
//
import UIKit
import XLPagerTabStrip
class ViewedViewController: UIViewController, IndicatorInfoProvider, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
let heightAdjustment: CGFloat = 80.0
let bcolor : UIColor = UIColor( red: 0.2, green: 0.2, blue:0.2, alpha: 0.3 )
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 20
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = UIStoryboard(name: "ProductDetail", bundle: nil).instantiateViewController(withIdentifier: "ProductDetail")
let nav = AppDelegate.current().window?.rootViewController as? UINavigationController
nav?.pushViewController(vc, animated: true)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ViewedProductCell", for: indexPath) as! ViewedProductCell
cell.layer.borderColor = bcolor.cgColor
cell.layer.borderWidth = 0.5
cell.backgroundColor = UIColor.white
cell.lblTitleProductViewed.text = "Super Aqua"
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let layout = collectionViewLayout as! UICollectionViewFlowLayout
let width = collectionView.frame.size.width / 3
let cellSize = CGSize(width: width, height: width + heightAdjustment)
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
layout.itemSize = cellSize
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
layout.scrollDirection = .horizontal
return cellSize
}
// MARK: - Info untuk tab
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "VIEWED")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment