The UICollectionViewDelegateFlowLayout protocol defines methods that let you coordinate with a UICollectionViewFlowLayout object to implement a grid-based layout. The methods of this protocol define the size of items and the spacing between items in the grid.
Questions tagged [uicollectionviewdelegateflowlayout]
33 questions
7
votes
2 answers
Screen goes black after segue
I have tried to debug this but to no avail.
Basically when I segue from the first view controller to the second view controller the screen goes black momentarily. The code performs as I want it to but the screen going black is a bit of a pain for…

mick1996
- 516
- 9
- 31
4
votes
1 answer
UICollectionView cell ignores UICollectionViewDelegateFlowLayout - sizeForItemAt
I am trying to layout the size of my collectionViewCell so that in each row there are 7 cells (easy right?).
The cell is very simple, it only has a UILabel with top, left, bottom and right constraints of 0.
I have setup the sizeForItemAt method as…

Shadi Habiballah
- 73
- 5
2
votes
2 answers
UICollectionView sizeForItemAt Called But Not Sized Correctly
I would like to have the first section's cells be the full width of the collection view and the second section be half of the width. On startup, the cells don't respect the given width although the height seems to be respected. After a couple of…

Nicholas Bastarache
- 71
- 1
- 6
2
votes
3 answers
issue while set dynamic width of collection view cell
I am trying to dynamically set the width of collection view cell. Initially it's not rendering as expected. But when I tap on the cell, its getting adjusted as I want. Here's the code that I wrote:
Code
import UIKit
class ViewController:…

Vishal Parmar
- 615
- 4
- 31
2
votes
3 answers
CollectionView method 'referenceSizeForHeaderInSection' throws exception
I am trying to create headers for my collectionView with dynamic height. But when I implement "referenceSizeForHeaderInSection", the app crashes with the following exception:
Terminating app due to uncaught exception…

Vyshakh
- 632
- 1
- 11
- 29
1
vote
1 answer
Scaling down the height of a UICollectionViewCell dynamically
I am using UICollectionViewDelegateFlowLayout to display cells of dynamic height in my Collection View. The size of the cells are set in sizeForItemAt.
Goal: Each Collection View cell has a toggle function that should change the…

Joe
- 3,772
- 3
- 33
- 64
1
vote
1 answer
UICollectionView layout behave weirdly on scrolling
I'm setting a collection View in order to display content as on instagram. instagram's grid
In order to set the layout I'm using some delegate methods of UIcollectionviewDelegateFlowLayout :
extension ProfileViewController :…
user12422782
1
vote
3 answers
Collection View Cells are resizing unintentionally when scrolling to bottom of CollectionView
I am building a collection view (gallery) of images.
The layout is 3 cells per row.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
…

Peter Irving
- 305
- 2
- 10
1
vote
0 answers
Is there a way to return the size calculated by constraints in the sizeForItemAt UICollectionViewDelegateFlowLayout method
I'm overriding the sizeForItemAt method of UICollectionViewDelegateFlowLayout. What I'd like to do is only calculate the size if I'm in a certain section, and fall back to the default flow layout behaviour for the other sections.
I'm not entirely…

mike
- 2,073
- 4
- 20
- 31
1
vote
1 answer
How to make 2 rows in horizontal collection view without using sections
The horizontal scrolling in UICollectionView only returns one row and I need to make a horizontal scrolling collection view with 2 rows just like the image below
[1]: https://i.stack.imgur.com/Vs1kt.png :[1]

imgroot
- 131
- 3
- 11
1
vote
1 answer
Exception in collectionView(_:layout:sizeForItemAt:) when accessing layout.collectionViewContentSize
Achieve
I want to have two different item sizes in a UICollectionView. Therefore I've implemented
collectionView(_:layout:sizeForItemAt:) of UICollectionViewDelegateFlowLayout.
Error
But I'm facing the problem that my app crashes with an exception…

Aaron
- 413
- 5
- 13
1
vote
0 answers
Right way to add collection view without behaviour of the UICollectionViewFlowLayout is not defined warning
My requirement is to have a slider collection view on top of my view in ViewController. I've tried many work around for my requirement (You can see that in my collection view setup code). But, time I receive the warning about The behavior of the…

Frankenstein
- 15,732
- 4
- 22
- 47
0
votes
0 answers
UICollectionView minimumLineSpacing bug
I'm creating a horizontal scroll view through the collection view.
I used flowlayout for layout, and I set the scroll direction to horizontal.
I found a bug in this situation.
If the width of the item is different, line spacing is not applied, but…

hooose
- 1
- 1
0
votes
0 answers
Layout problem in UICollectionView when reloading
I am using an UICollectionView to display a list of items in a 2 column layout with equal size of columns. This is obtained by a flow-layout.
Simple.
However, the first row is different from the rest, as it can vary from being full "screen" width or…

Developer-1
- 163
- 8
0
votes
0 answers
iOS - UICollection view with resizable cells on scroll with CompositionalLayout
I need a collection view with cells that are resizing on scroll as in the screen recording.
I can do this with Flow layout, but have no idea how can I achieve this behaviour with Compositional layout?

Marta Paniti
- 152
- 6