Collectionview height based on label text iOS swift
Problem:
I want to show the collection view cell height to be dynamic based on the label text.How can i achieve that?
Solution:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let screenSize = UIScreen.main.bounds
let size = (screenSize.width) / CGFloat(1)
var collheight = 30.0
if let item = mystring {
let labelHeight = item.content?.height(withConst
collheight = labelHeight! + 50
}
return CGSize(width: size, height: collheight)
}
Comments
Post a Comment