Search code examples
iosswifttableviewcollectionview

how can i stretch collectionView height in tableViewCell?


i want to stretch collectionView height in tableView.

as the gitHub App's Label (below picture),
when the collectionViewCell's width excess collectionView's width,
I want to set collectionViewCell in a new line

To set cell in the new line, i tried to use flowlayout.
but it did not be increased height. just can scroll in collectionView. 😭.
unfortunately, tableView's height did not be increased

what's the best way to do this ?😂

enter image description here enter image description here enter image description here


Solution

  • This approach from SRP-Achiever should work.

    override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
            collectionView.layoutIfNeeded()
            collectionView.frame = CGRect(x: 0, y: 0, width: targetSize.width , height: 1)
            return collectionView.collectionViewLayout.collectionViewContentSize
    }