0

I am working with UICollectionView which has custom UICollectionViewLayout.I need spacing around UICollectionViewCell like i can get if i use UICollectionViewFlowLayout with this minimumInteritemSpacingForSectionAtIndex and minimumLineSpacingForSectionAtIndex.

This properties are not in UICollectionViewLayout. So how i can manage spacing between UICollectionViewCell in swift 2.1 or any idea?

I have tried this

        let bcolor : UIColor = UIColor.whiteColor()
        dataCell.layer.borderColor = bcolor.CGColor
        dataCell.layer.borderWidth = 0.9
        dataCell.layer.cornerRadius = 3

any better idea?

Sofeda
  • 1,361
  • 1
  • 13
  • 23

1 Answers1

0

After a stupid amount of research I think that this code provides a skeleton for what you need:

import UIKit

class UICVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {
    // You probably want to implement this
    func collectionView(collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSize(width: 100, height: 100)
    }

    func collectionView(collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
        return CGFloat(10)
    }

    func collectionView(collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
        return CGFloat(10)
    }

}

let uicv = UICollectionView()
uicv.delegate = UICVC()

This code ensures that the Collection View's cells are the right size. Assuming your collection view is a standard grid, this should work well for sizing the cells. Positioning of content within cells is another matter, of course.

BallpointBen
  • 9,406
  • 1
  • 32
  • 62