I did what this answer said but it did not work why?
but there is a problem its not resizing what am i missing out
I have also faced same issue so I did another approach. You need to add width constraint and you need to set it constant in systemLayoutSizeFitting function.
The main thing you should be careful about that is add all subviews to contentView of cell and also the last subview must has a constraint to bottom of contentView like the autoResizing TableViewCell
class ABCCell: UICollectionViewCell {
lazy var width: NSLayoutConstraint = {
let width = contentView.widthAnchor.constraint(equalToConstant: bounds.size.width)
width.isActive = true
return width
}()
override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
width.constant = bounds.size.width
return contentView.systemLayoutSizeFitting(CGSize(width: targetSize.width, height: 1))
}
}