Questions tagged [uicollectionviewflowlayout]
209 questions
33
votes
5 answers
UICollectionViewFlowLayout estimatedItemSize does not work properly with iOS12 though it works fine with iOS 11.*
For UICollectionView's dynamic height cells we use,
if let layout = self.collectionViewLayout as? UICollectionViewFlowLayout {
layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
}
with the proper constraint of height and width,…

Aman Gupta
- 985
- 1
- 8
- 18
31
votes
8 answers
UICollectionView - distance between cells?
I'm using a UICollectionView with the cell width of 67, right now I am using a flow layout.
I have 3 cells in a row with 30px space between cells. How can make that distance less, so that I can fit four cells in a row? Does this method have…

Sarabyte Studios
- 1,336
- 2
- 13
- 16
10
votes
1 answer
invalidateLayout with invalidateSupplementaryElements and UICollectionViewLayoutInvalidationContext
I am trying to refresh a Footer ( supplementaryElement). I am using the invalidatelayout method. Based on SO suggestions here. Apple documentation here.
I am getting the following error:
Terminating app due to uncaught exception…

Jack tileman
- 813
- 2
- 11
- 26
9
votes
1 answer
DecorationView gets resized when AutoSizing cells are enabled in UICollectionViewFlowLayout
Environment:
UICollectionView that looks like UITableView
Custom UICollectionViewFlowLayout subclass to define the frame of the DecorationView
Self-Sizing cells enabled
Expected behavior:
A DecorationView that should be placed as a background for…

Richard Topchii
- 7,075
- 8
- 48
- 115
6
votes
1 answer
Need Header on Top for Horizontal UICollectionView UIKIT
I am implementing custom headers for UICollectionView
I need a header on the Top for Horizontal CollectionView.

Dc7
- 1,405
- 1
- 10
- 16
5
votes
3 answers
UICollectionView sticky header disappears for while after inserting section when collection is overscrolled (bounce effect)
I'm using UICollectionReusableView as a header of UICollectionView section. I enabled "sticky headers" with:
let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout
layout?.sectionHeadersPinToVisibleBounds = true
I'm…

Jakub Marek
- 164
- 7
5
votes
0 answers
Does setting estimatedItemSize on UICollectionViewFlowLayout break UICollectionViewDataSourcePrefetching?
I am creating a UICollectionView with cells of dynamic height and using estimatedItemSize property on UICollectionViewFlowLayout (Apple Docs Reference).
Although, I noticed that once I set the estimatedItemSize property, my prefetchItemsAt method…

Elitecoder
- 170
- 1
- 13
4
votes
0 answers
How do I create stretchy header in compositional layout?
class StretchyHeader: UICollectionViewFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let layoutAttributes = super.layoutAttributesForElements(in: rect)! as…

skylin
- 51
- 4
4
votes
1 answer
iOS Collection view flow layout dynamic row height with max height of item in row
I want to create collection view cells which should have max height of item in row. Each item is having dynamic height. Wanted to stretch cells to maximum row height.
Attached the screenshot for same below:
So i would like to stretch item 1 & item…
4
votes
1 answer
CollectionViewSection Inset Does Not Consider Header/Footer Views
I have a collectionView with headers and footers. I want to add spacing at the end of the section.
I am using:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section:…

David Henry
- 1,972
- 20
- 43
4
votes
1 answer
UICollectionView showing vertically even when scroll direction is set to horizontal?
I am trying to paint UIScrollView list horizontally using this code but not working expected?
let nib = UINib(nibName: cellIdentifier, bundle: nil)
collectionView.register(nib, forCellWithReuseIdentifier: cellIdentifier)
…

iamVishal16
- 1,780
- 18
- 40
4
votes
2 answers
How to align cell to top by Flow Layout in CollectionView
In this code I am trying to change the size of the first cell of the UICollectionView and the others with the same size but in the first row only one cell is coming out when I want two to come out:
func collectionView(_ collectionView:…

Reinier Isalgue
- 43
- 7
4
votes
2 answers
UICollectionView items order not reversed in right to left languages
I noticed a big issue where in right to left languages, the cells order is not properly reversed, only the alignment is correct. But only for horizontal flow layout, and if the collection view contain different cell sizes! Yes, I know this sound…

Ludovic Landry
- 11,606
- 10
- 48
- 80
4
votes
1 answer
How do I center align my collectionView cells?
I tried this solution here but it seems to only work for vertical layout. I'm trying to make it work for a horizontal layout. In my case, I always want 3 cells on top and 2 on bottom that is center aligned.
Example:

Oranges
- 51
- 3
- 5
4
votes
0 answers
Detecting end of UICollectionView reorder
I want to provide the option of UICollectionView reordering while locking the first n cells.
In order to denote that the first n cells are "locked" (cannot be reordered) I want to change their background colors to a light gray.
So far I've been able…

huddie96
- 1,240
- 2
- 13
- 26