1

I have a UITableView with different cells, within one of these cells is a UIStackView which contains multiple UIView's, the last one being a custom class that subclasses UICollectionView.

So the issue I'm having is that the collectionview within the stackview doesn't appear because the height is zero. To try and get around this issue, within the custom UICollectionView I've tried to apply a height within using the following piece of code.

override func layoutSubviews() {
    super.layoutSubviews()
    if !hasBeenLayedOut {
        hasBeenLayedOut = true
        self.apply(height: self.collectionViewLayout.collectionViewContentSize.height, width: nil)
        self.layoutIfNeeded()
    }
}

The only problem is because after the views in the stack views have constraints applied once I apply a height constraint, the stack view items shrink to adjust their content to the collection view.

My questions is it possible to figure out the height of the collectionview before layoutSubviews()? I've tried to use the collectionviewContentSize but it's always 0 which is why my collectionview doesn't have a height.

Tunds
  • 1,804
  • 2
  • 15
  • 30

0 Answers0