Different cell size in UICollectionview

后端 未结 4 2198
梦谈多话
梦谈多话 2020-12-18 18:10

In my iphone app,I am showing images on a collection view. I fetch the images from urls,with urls I get the image size also. eg:- let\'s say there are two kinds of images la

4条回答
  •  春和景丽
    2020-12-18 18:41

    For swift extend the flowlayout to you viewcontroller, if you need to show dynamic images on cell make variable which hold images name into your view contorller and use this:

    let imageData = ["image1","image2","image3","image4"]
    
    extension yourViewController: UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    
        let photo = UIImage(named: imageData[indexPath.row])
            return CGSize(width: (photo?.size.width)!, height: (photo?.size.height)!)
    
    }
    

    }

提交回复
热议问题