duyn9uyen
duyn9uyen

Reputation: 10311

Remove all cell space from UICollectionView

Piggy backing off this SO question,

If I change

 cell.layer.borderWidth = 0.0

it removes the border from the top and bottom of the cell but won't remove the left and right borders. http://imgur.com/c2oDzjc Is there anyway of removing all borders and cell spacing so that the image is completely flush? My code:

var collectionView: UICollectionView?
var screenSize: CGRect!
var screenWidth: CGFloat!
var screenHeight: CGFloat!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    screenSize = UIScreen.mainScreen().bounds
    screenWidth = screenSize.width
    screenHeight = screenSize.height

    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 0

}

func collectionView(collectionView: UICollectionView,
    cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell: CollViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellIdentifier", forIndexPath: indexPath) as! CollViewCell
    //cell.imageCell.image = UIImage(named: self.gridIMages[indexPath.row])

    cell.backgroundColor = UIColor.whiteColor()
    cell.layer.borderColor = UIColor.blackColor().CGColor
    cell.layer.borderWidth = 0.0
    cell.frame.size.width = screenWidth / 3
    cell.frame.size.height = screenHeight / 3

    return cell
}

Upvotes: 1

Views: 2397

Answers (1)

Stefan Salatic
Stefan Salatic

Reputation: 4513

You aren't assigning your layout anywhere. You just create it and don't use it.

So you need collectionView.collectionViewLayout = layout in the viewDidLoad. But it might be easier to just set it in interface builder.

Upvotes: 2

Related Questions