0

I have a screen in interface builder that consists of a UI Collection View containing reusable cells. I've used Interface builder to add Auto Layout constraints to the UI Collection view and its scaling and moving about on each device like it should. How can I use the same method (control dragging) to auto layout the cells width and height? I can get constraint options via control dragging for the child objects in the cell to the cell but not from the cell to say the UI Collection View.

Any help greatly appreciated!

Thanks.

Dennis Vennink
  • 1,083
  • 1
  • 7
  • 23
Krivvenz
  • 3,911
  • 3
  • 22
  • 32
  • You cannot use auto layout to set the size of a cell, and the size of cells cannot influence the size of the collection view. So it's a bit hard to see what you're after here. – matt Oct 24 '17 at 21:49
  • 2
    Possible duplicate of [How do I set collection view's cell size via the auto layout](https://stackoverflow.com/questions/38025112/how-do-i-set-collection-views-cell-size-via-the-auto-layout) – nathangitter Oct 24 '17 at 21:51

1 Answers1

0

You don't. Collection views manage the placement of the cells within the view themselves, using their own rules. You can certainly use AutoLayout to determine the size and placement of the entire collection view, and you can use it for the internal layout of individual cells, but you can't use AutoLayout to size or position the cells within the collection view.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • So my understanding is the only way to re-size collection view cells is by using collectionView(_:layout:sizeForItemAt:). Does anyone know if this function runs before the Interface Builder constraints are added? I need to size the content of my cells based on the width of the cell and the cell need to scale in size per device. – Krivvenz Oct 25 '17 at 08:48