2

in my app there is a image on top of the collectionview header and i need the collectionview under the nav bar IT looks like this

but needs to be like this

Tye Howatt
  • 105
  • 2
  • 9
  • Possible duplicate http://stackoverflow.com/questions/43023384/uicollectionview-remove-top-padding/43025517#43025517 – Joe Apr 27 '17 at 16:32

5 Answers5

3

Select the collection view, go to size inspector and set the content insets to never in the scroll view section

  • it may also be necessary to set `(self.collectionViewLayout as! UICollectionViewFlowLayout).sectionInsetReference = .fromContentInset` – bbjay Apr 22 '19 at 22:05
0

set automaticallyAdjustsScrollViewInsets to true (it should be by default). You can do this in code or in the storyboard by selecting the view controller.

If that doesn't fix your issue you should adjust your autolayout constraints. if you can show how you have created the view layout I can guide you further.

Scriptable
  • 19,402
  • 5
  • 56
  • 72
0

You can set collectionView constraints to the bottom of topLayoutGuide in your UIViewController:

collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 0).isActive = true
Alexandre Lara
  • 2,464
  • 1
  • 28
  • 35
0

You need to set the collectionView top constraint to view top constraint, not the topLayoutGuide bottom (as topLayoutGuide bottom is the bottom of navigation bar in your case).

Vojta Rujbr
  • 325
  • 3
  • 11
0

Set the collection view's contentInsetAdjustmentBehavior to .never.

Source

abc123
  • 8,043
  • 7
  • 49
  • 80