sakoaskoaso
sakoaskoaso

Reputation: 347

Swift how to give a uicollectionview automatic height?

I want to give my uicollectionview automatic height.I found this code

self.flowLayout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize

But it didn't tell what flowLayout is,so it didn't work

Upvotes: 0

Views: 135

Answers (1)

Phyber
Phyber

Reputation: 1368

You can set its height like so:

collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.heightAnchor.constraint(equalToConstant: collectionView.contentSize.height).isActive = true

Or by setting its frame:

collectionView.frame = CGRect(x: x, y: y, width: width, height: collectionView.contentSize.height)

Upvotes: 1

Related Questions