Questions tagged [uicollectionviewlayout]

The UICollectionViewLayout class is an abstract base class that is used to generate layout information for a collection view.

The UICollectionViewLayout class is an abstract base class that you subclass and use to generate layout information for a collection view. The job of a layout object is to determine the placement of cells, supplementary views, and decoration views inside the collection view’s bounds and to report that information to the collection view when asked. The collection view then applies the provided layout information to the corresponding views so that they can be presented onscreen.

More: UICollectionViewLayout Class Reference

1496 questions
43
votes
4 answers

Reorder cells of UICollectionView

Consider a UICollectionView with flow layout and horizontal direction. By default, cells are ordered from top to bottom, left to right. Like this: 1 4 7 10 13 16 2 5 8 11 14 17 3 6 9 12 15 18 In my case, the collection view is paged and it has been…
hpique
  • 119,096
  • 131
  • 338
  • 476
39
votes
4 answers

UICollectionView wrong contentSize on first load, correct after that

I have a common UICollectionView with paging and all. Still trying to figure out why on viewDidLoad:, viewWillAppear: and viewDidAppear: , only on first view call, I get the wrong size when calling myCollectionView.collectionView.contentSize.width.…
klauslanza
  • 671
  • 1
  • 6
  • 8
38
votes
1 answer

Custom animation when switching from one UICollectionViewLayout to another?

As a test I made one layout that displays cells in a vertical line and another that displays them in a horizontal layout. When I call [collectionView setCollectionViewLayout:layout animated:YES]; it animates between the two positions very…
Mason Cloud
  • 1,266
  • 1
  • 15
  • 20
38
votes
21 answers

UICollectionViewFlowLayout Size Warning When Rotating Device to Landscape

We are using a UICollectionView to display cell that cover the full screen (minus the status and nav bar). The cell size is set from self.collectionView.bounds.size: - (void)viewWillAppear:(BOOL)animated { // // value isn't correct with the…
37
votes
11 answers

UICollectionView Custom Cell to fill width In Swift

I've been trying to figure-out how can i make the cell fill the width, as you can see in the picture the width between the cells is too big. i am using custom cell with only one imageView. I tried to customize it from the storyboard but i guess…
AaoIi
  • 8,288
  • 6
  • 45
  • 87
36
votes
7 answers

Warning: UICollectionViewFlowLayout has cached frame mismatch for index path 'abc'

This is the code causing the warning: private override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { let attributes = super.layoutAttributesForItemAtIndexPath(indexPath) let distance =…
Dhruv Goel
  • 2,715
  • 1
  • 17
  • 17
36
votes
6 answers

UICollectionView with a sticky header

I found a blog on how to make sticky headers and it works great. Only thing is I don't think it takes into account the sectionInserts. This is how its intended to look: I have my inserts: collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(16,…
Padin215
  • 7,444
  • 13
  • 65
  • 103
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,…
33
votes
5 answers

Using Invalidation Contexts for UICollectionViewLayout

So I have implemented working sticky headers in my UICollectionView in part by returning YES from shouldInvalidateLayoutForBoundsChange:. However, this impacts performance and I do not want to invalidate the entire layout, only my header…
mattsson
  • 1,329
  • 1
  • 14
  • 30
32
votes
1 answer

Adding pinch zoom to a UICollectionView

Intro I'm going to describe the effect I want to achieve, and then I'll give detail on how I'm currently trying to implement this and what's wrong with its behaviour as it stands. I'll also mention another approach I've looked at but couldn't make…
30
votes
3 answers

UICollectionView Header and Footer View

I'm using a UICollectionView and need a global header and footer together with section headers. Both global header and footer are supposed to scroll with the rest of the content. Basically they should work exactly like UITableView's tableHeaderView…
paul
  • 403
  • 1
  • 4
  • 6
29
votes
2 answers

Flow layout animation glitch when inserting multiple custom supplementary views

When inserting multiple custom supplementary views in a collection view with existing supplementary views, using a subclass of UICollectionViewFlowLayout, the collection view appears to create glitched animations or otherwise not handle the…
jamesk
  • 3,807
  • 21
  • 38
29
votes
7 answers

UICollectionView exception in UICollectionViewLayoutAttributes from iOS7

I have done a View in CollectionView with CustomLayout. In iOS6 it worked great but iOS7 it throws an exception like this. Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'layout attributes for supplementary…
Jirune
  • 2,310
  • 3
  • 21
  • 19
29
votes
2 answers

Independent scrolling for each section of a UICollectionView?

Is it possible to use UICollectionView to build a layout where each section can be independently scrolled? For example, imagine 20 rows of images, where each row could be scrolled independently horizontally to reveal more images offscreen (without…
MikeV
  • 1,220
  • 2
  • 13
  • 17
27
votes
6 answers

Adding padding to first and last cell of UICollectionView

I have subclassed UICollectionViewFlowLayout to get horizontal UICollectionView with paging like behavior. It works perfectly fine as long as UICollectionViewCell is not first of last cell. Images attached below. Do I need to override something…