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
18
votes
3 answers

How to snap horizontal paging to multi-row collection view like App Store?

I would like to replicate the paging in the multi-row App Store collection view: So far I've designed it as close as possible to the way it looks, including showing a peek to the previous and next cells, but do not know how to make the paging to…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
18
votes
4 answers

UICollectionView contentOffset after device rotation

What I am trying to do: On Apple's Photo's App, if you rotate device while scroll to an arbitrary offset, same cell that was in the center beforehand would end up in the center after the rotation. I am trying to achieve the same behavior with…
Gizmodo
  • 3,151
  • 7
  • 45
  • 92
18
votes
2 answers

sizeForItemAtIndexPath is not found in different swift versions

I am using UICollectionView but following method not found: func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize please suggest me it's…
Vikram Biwal
  • 2,618
  • 1
  • 25
  • 36
17
votes
5 answers

Adjust collectionView.scrollToItem to consider inset?

I'm sometimes scroll to the left of a cell like this: collectionView.scrollToItem( at: IndexPath(row: 5, section: 0), at: .left, // TODO: Left ignores inset animated: true ) This is how it starts out before scrollToItem…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
17
votes
3 answers

Header of section in UICollectionView with custom UICollectionViewLayout

I'm working on UICollectionView with custom layout. In two days I cannot understand how add header to UICollectionView. I've got very simple view controller (created in storyboard with custom layout): class ACollectionViewController:…
Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
17
votes
2 answers

Display section header on top with UICollectionViewFlowLayout scrolling set to horizontal

This is a duplicate of this question. I'm asking again because the accepted answer is not working and no one's providing more explanation on how the supposed correct answer works. So here's the situation: I want to display the collection view into…
Anna Fortuna
  • 1,071
  • 2
  • 17
  • 33
17
votes
1 answer

Animate UICollectionView cell size change and reposition surrounding cells

Goal: To animate the change of a cell's height and reposition surrounding cells. Scenario: Some cells in a collection view load remote images. Initially, those cells are sized statically and an activity indicator is shown. After an image is…
17
votes
10 answers

UICollectionView and Supplementary View (header)

Trying to add a a Supplementary view into my UICollectionView as a header. I'm having issues getting it to work. I use a custom UICollectionViewFlowLayout to return a contentSize that is always at least 1 pixel larger then the frame (I am using a…
Padin215
  • 7,444
  • 13
  • 65
  • 103
16
votes
10 answers

setCollectionViewLayout:animated causing debug error: Snapshotting a view that has not been rendered results in an empty snapshot

I am busy with UICollectionView in iOS7. I am changing my collection view's layout between two different layouts. Which are a subclass of UICollectionViewFlowLayout. This is how I change views when a button is tapped:…
Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99
16
votes
5 answers

UICollectionView Cell Overlap

I have a horizontal UICollectionView. I want to make the cells overlap each other by a certain amount of 60 pixels so that the second cells overlaps the first by 60 pixels and the third overlaps the second by the same amount and so on. I tried sub…
16
votes
2 answers

UICollectionViewFlowLayout vs subclassing UICollectionViewLayout

I know the documented advice is to use UICollectionViewFlowLayout if you are doing anything "like a grid or a line-based breaking layout". However, I am not sure this is true for my case. I want a grid but do not want a line-breaking layout. Items…
Jeff
  • 3,829
  • 1
  • 31
  • 49
15
votes
8 answers

UICollectionViewCompositionalLayout with groupPagingCentered doesn't start centered

My layout code is very simple, something that you will have seen in every tutorial or article about the new compositional layouts. func createLayout() -> UICollectionViewLayout { let itemSize = NSCollectionLayoutSize(widthDimension:…
Kevin Renskers
  • 5,156
  • 4
  • 47
  • 95
15
votes
6 answers

How to get 1 pixel width borders in UICollectionView cells? (code provided)

How can I get a pixel perfect one (1) pixel with border line in a UICollectionView (e.g. to make a month calendar). The issue is that where cells meet, their borders meet, so it is effectively 2 pixels (not 1 pixel). Therefore this is a…
Greg
  • 34,042
  • 79
  • 253
  • 454
15
votes
2 answers

Animate a UICollectionView cell on selection

I have a basic grid in a UICollectionView. It's a simple 2 column, multiple row layout using the UICollectionViewDelegateFlowLayout. When a cell is selected, I want to dim the background, float the cell to the center of the screen and then have a…
14
votes
1 answer

UICollectionViewLayout and method layoutAttributesForItem is never called

I am trying to implement a UICollectionViewFlowLayout or UICollectionViewLayout - any ways the layoutAttributesForItem is never called. I can see from others that they call layoutAttributesForItem from self.layoutAttributesForItem. Like this flowout…
Chris G.
  • 23,930
  • 48
  • 177
  • 302