how to fit collection view cell in table view cell ( adaptive on all screen sizes?)

80 Views Asked by At

My collection view cells (7 cells) need to fit into table view cell, but when I run it it shows differently in iPhone 6 and iPhone X . Is there any way that I can overcome the issue?

enter image description here Let's say I have 2 collection views which should cover and fit adaptively on different device screen sizes.

1

There are 1 best solutions below

1
Rishabh Shukla On

In your custom UITableViewCell

 override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
    self.contentView.frame = self.bounds
    self.contentView.layoutIfNeeded()
    self.collectionView.reloadData()
    return self.collectionView.contentSize
}

and when u are configuring the cell means u are passing data From controller to your UITableViewCell use this in that

self.collectionView.layoutIfNeeded()
self.contentView.layoutIfNeeded()