Im trying to create collection view (Expected View) with half width and dynamic height based on given text.
I am trying to achieve this by (Code in ViewController)
let flowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
flowLayout.estimatedItemSize = CGSize(width: (UIScreen.main.bounds.width / 2), height: 2000.0)
flowLayout.itemSize = UICollectionViewFlowLayout.automaticSize
And (Code in UICollectionviewCell)
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
setNeedsLayout()
layoutIfNeeded()
let size = contentView.systemLayoutSizeFitting(layoutAttributes.size)
var frame = layoutAttributes.frame
frame.size.height = ceil(size.height)
layoutAttributes.frame = frame
return layoutAttributes
}
By using the above code, I can achieve to create collectionview Actual view (half width and dynamic height). But collection view cell height not equal to the adjacent. Actually this collection view cell height should be same as adjacent cell height(which is having the maximum height). How to update the cell size based on the adjacent cell size?
Thanks in advance