-1

I have a custom flow layout. I know where my cells need to be. I currently create specific frames for each cell. However, I'm worried about different sized iPhones so I want to explore creating constraints. I know this has to be done in the function prepareForLayout().

override func prepareLayout() {
    for item in 0 ..< collectionView!.numberOfItemsInSection(0){
        let indexPath = NSIndexPath(forItem: item, inSection: 0)
        let attributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
        cache.append(attributes)
    }
    //This is where I want to do work for creating constraints for my cells
}

I guess the question is can you create constraints between cells when creating your own custom flow layout

jDoe
  • 61
  • 1
  • 5

1 Answers1

0

the question is can you create constraints between cells when creating your own custom flow layout

No. Constraints and collection view layout are opposites. The collection view layout positions items by frame.

However, you know what the collection view dimensions are (self.collectionView!.bounds.size), so your item frames can take account of that. And they should do so! After all, that is how a normal flow layout works when it spaces out a row so that it is right-and-left justified. It's just a matter of doing a little elementary arithmetic.

matt
  • 515,959
  • 87
  • 875
  • 1,141