1

I have a UICollectionView like this:

enter image description here

enter image description here

enter image description here

These are the three different cases for it. Light grays shows the borders of the collection view and dark gray is for cells. I have set min spacing and section insets to 0. But still I am getting these unwanted insets, and it seems it only happens when there are more than 1 cell.

I calculate the item sizes like this:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    guard let item = place?.publicTransports?[indexPath.row] else {
        return CGSize.zero
    }

    var lines = ""
    for (i, line) in item.lines.enumerate() {
        lines.appendContentsOf(line)
        if i != item.lines.count - 1 {
            lines.appendContentsOf(", ")
        }
    }

    let linesString = lines as NSString
    return CGSize(width: linesString.sizeWithAttributes(nil).width + 35 + 20, height: collectionView.bounds.height/2)
}

Any suggestions?

Tomer Ciucran
  • 169
  • 1
  • 9

1 Answers1

6

It seems the question should read, left align a UICollectionView.

The simplest solution is to go to:

https://github.com/mokagio/UICollectionViewLeftAlignedLayout

And subclass your layout to this, this will ensure your UICollectionView left aligns, you should set all your insets to 0 first then begin changing them according to your design.

Sean Lintern
  • 2,961
  • 17
  • 25