How to set Random height of image
var cellHeight : Int = Int()
switch(Int(arc4random_uniform(4)))
{
case 1 :
cellHeight = 200
break
case 2 :
cellHeight = 230
break
case 3 :
cellHeight = 260
break
case 4 :
cellHeight = 290
break
default:
cellHeight = 320
break
}
dict.setValue(cellHeight, forKey: "cellHeight")
self.arrListing.add(dict)
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
if collectionView == listCollectionView
{
let padding: CGFloat = 30
let collectionViewSize = collectionView.frame.size.width - padding
return CGSize(width: collectionViewSize/2, height: CGFloat(((self.arrListing.object(at: indexPath.row) as! NSDictionary).value(forKey: "cellHeight") as? Int)!))
}
else
{
return CGSize(width: 50, height: 50)
}
}
Comments
Post a Comment