Last active
June 17, 2016 15:27
-
-
Save DamienBell/405a7830280642300924a10ad1e61d3c to your computer and use it in GitHub Desktop.
Quick Start for using UICollectionView
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
// Created by Damien Bell on 6/2/16. | |
// Copyright © 2016 Damien Bell. All rights reserved. | |
// | |
import UIKit | |
class DemoUICollectionViewController: UIViewController, | |
UICollectionViewDataSource, | |
UICollectionViewDelegateFlowLayout{ | |
@IBOutlet weak var collectionView: UICollectionView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
collectionView.contentInset = UIEdgeInsets(top: 68.0, left: 0, bottom: 20.0, right: 0) | |
//register cells | |
collectionView.registerNib(UINib(nibName: "CustomCell", bundle: nil), forCellWithReuseIdentifier: "CustomCell") | |
//create layout | |
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() | |
layout.sectionInset = UIEdgeInsets(top: 8.0, left: 0.0, bottom: 0.0, right: 0.0) | |
layout.minimumLineSpacing = 0.0 | |
layout.minimumInteritemSpacing = 0.0 | |
collectionView.collectionViewLayout = layout; | |
collectionView.dataSource = self; | |
collectionView.delegate = self; | |
} | |
// MARK: - UICollectionViewDataSource | |
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { | |
return 0 | |
} | |
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{ | |
return 0 | |
} | |
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{ | |
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CustomCell", forIndexPath: indexPath) //as CustomCellSubclass | |
return cell | |
} | |
// MARK: - UICollectionViewDelegateFlowLayout | |
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{ | |
return CGSizeZero | |
} | |
func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool{ | |
return true | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment