         cell.backgroundColor = FlatUIColors.randomFlatColor()
         return cell
     }
+    
+    
+    // MARK: === UICollectionViewDelegateFlowLayout ===
+    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
+        guard let layout = collectionViewLayout as? UICollectionViewFlowLayout else {return CGSizeMake(30, 30)}
+        
+        let xTotalWhitespace = layout.sectionInset.left + layout.sectionInset.right + layout.minimumInteritemSpacing * CGFloat(numCols - 1)
+        let yTotalWhitespace = layout.sectionInset.top + layout.sectionInset.bottom + layout.minimumLineSpacing * CGFloat(numRows - 1)
+        
+        let availableWidth  = Int(collectionView.bounds.width  - xTotalWhitespace)
+        let availableHeight = Int(collectionView.bounds.height - yTotalWhitespace)
+        
+        let itemHeight = availableHeight / numRows
+        let itemWidth  = availableWidth / numCols
+        let itemSize = CGSizeMake(CGFloat(itemWidth), CGFloat(itemHeight))
+        //        let itemSquareDimension = min(itemWidth, itemHeight)
+        //        let itemSize = CGSizeMake(CGFloat(itemSquareDimension), CGFloat(itemSquareDimension))
+        
+        return itemSize
+    }
+    
+    
+    //ViewController Ends here
 }
 
 extension FlatUIColors {

    
    // MARK: === UICollectionView dataSource ===
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 32
    }
    
    // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:

        layout.minimumInteritemSpacing = 1.0
        layout.sectionInset = UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)
        layout.estimatedItemSize = CGSizeMake(30, 30)
        
        
        let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
