I have a collectionview with dynamic width cells & scroll is vertical. So when first two text are small and third is large, the two cells are leaving more space in between them and third one getting down in second row. I want 1st and 2nd cell to keep inter-item-spacing intact and leave extra space at the end of the row.
kindly check attachment for the issue. I hope i’m clear with the requirement.
here the 1st and 2nd also should be just like the 3rd line. leave extra space at the end of the row. is it possible?
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if property.keySizeGuide?.lowercased().contains("size") ?? false {
return setTextCellSize(path: indexPath)
}
if let imgUrl = property.nameValues?[indexPath.row].imgUrl, !imgUrl.isEmpty && checkForImageColorValues().0 {
return CGSize(width: 96, height: 96)
}
if let hexColor = property.nameValues?[indexPath.row].hexColor, !hexColor.isEmpty && checkForImageColorValues().1 {
return CGSize(width: 48, height: 48)
}
return setTextCellSize(path: indexPath)
}
private func setTextCellSize(path: IndexPath) -> CGSize {
let widthLabel = property.nameValues?[path.row].value.width(withConstraintedHeight: 20, font: .systemFont(ofSize: 14, weight: .semibold)) ?? 0
return CGSize(width: widthLabel+45, height: 48)
}





