1. Construction
var flowLayOut = UICollectionViewFlowLayout()
var collectionView: UICollectionView? //must be optional
2. Setting
Frequently-used properties for flowLayOut:
itemSize, minimumInteritemSpacing, minimumLineSpacing, scrollDirection
collectionView = UICollectionView(frame: CGRect(...), collectionViewLayout: flowLayOut)
Frequently-used methods for collectionView:
reloadData()
deselectItemAtIndexPath()
3. Delegate
UICollectionViewDataSource,
UICollectionViewDelegateFlowLayout
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
collectionView.registerClass(myCollectionViewCell.self, forCellWithReuseIdentifier: "myCell")
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("myCell", forIndexPath: indexPath) as? myCollectionViewCell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {}
4. Nesting
To nest a collectionView inside a collectionViewCell, do the exact same thing as if the collectionViewCell class is a VC. The only tricky part is passing values between the "big" collectionView and the "small" collectionView. I use customised delegate (refer to another blog about customised delegate).