Chris
Chris

Reputation: 2274

Swift CollectionView scrolls out of bounds

I have a CollectionView and the problem is that I have to set .masksToBounds = false so my Cells are displayed properly (their shadow to be specific). However that causes the CollectionView to scroll out of bounds which I certainly don't want. Is there a way to maybe only set maskstToBounds on the left and right ? Or is there any other workaround that might solve my issue here?

enter image description here

As you can see it scrolls at the top even though I set the theCollectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 30)

I hope my problem is clear. If you need any more info just let me know.

Upvotes: 0

Views: 590

Answers (1)

Hailey
Hailey

Reputation: 362

you have two problem, right?

first, you want set the shadow in a specific part

layer.shadowOffset = CGSize(width: 2, height: 0) 

If you want shadows only on the left and right, you can set the height at zero.

second, you want to set position

theCollectionView.translatesAutoresizingMaskIntoConstraints = false
theCollectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 30).isActive = true

Upvotes: 1

Related Questions