I want to custom a lot of layout size for each row of my collectionView
by using UICollectionViewDelegateFlowLayout
like below:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = view.frame.width
if indexPath.row == 0 {
return CGSize(width: width, height: 300)
}else if indexPath.row == 1 {
return dynamicSize // i want this size wrap its content
}
return CGSize(width: width, height:100)
}
I want dynamicSize that can wrap its content for some row. Anyone know how to do this?
Here is image of cell that i want dynamic size to wrap it.
I suggest you to use tableview instead of collectionview. It is very easy for you.
And for
cellForHeight
returnsUITableViewAutomaticDimension
. It will calculate your cell height itself and adjust it accordingly.Note: Make sure your constraints are proper.
Output: