Tye Howatt
Tye Howatt

Reputation: 105

How can i put my collection view under the navigation bar Swift

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

Upvotes: 2

Views: 3858

Answers (5)

abc123
abc123

Reputation: 8303

Set the collection view's contentInsetAdjustmentBehavior to .never.

Source

Upvotes: 0

Roy Rodriguez
Roy Rodriguez

Reputation: 59

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

Upvotes: 3

Vojta Rujbr
Vojta Rujbr

Reputation: 335

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).

Upvotes: 0

Alexandre Lara
Alexandre Lara

Reputation: 2568

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

Upvotes: 0

Scriptable
Scriptable

Reputation: 19750

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.

Upvotes: 0

Related Questions