将图像高度从图像 URL 设置为 PinterestLayout CollectionView

问题描述

我用 PinterestLayout 创建了一个 CollectionView,所以这是一个具有不同单元格高度的集合视图。这是可行的,但是当我使用 Firestore 将我的代码放入项目时(当我从 URL 获取单元格中的图像时)我遇到了问题,因为在这一行“let photo = post.floverImg”中,我想我必须输入类似的内容单元格“cell.imageView.sd_setimage(with: URL(string: flovers[indexPath.row].floverImg!))”显示图像而不是字符串。

扩展 HomeViewController { func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection 部分: Int) -> Int { 返回 flovers.count }

     func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell",for: indexPath) as! CustomCell
        cell.imageView.sd_setimage(with: URL(string: flovers[indexPath.row].floverImg!))
        cell.label.text = flovers[indexPath.row].floverName
      //  cell.descriptionLabel.text = flovers[indexPath.row].floverName
        cell.layer.cornerRadius = 15
        
        
    
        
        
       
        return cell
    }
}




func collectionView(collectionView: UICollectionView,heightForPhotoAt indexPath: IndexPath,with width: CGFloat) -> CGFloat
{
    
    if let post = posts?[indexPath.item],let photo = post.floverImg {
        let boundingRect = CGRect(x: 0,y: 0,width: width,height: CGFloat(MAXFLOAT))
        let rect = AVMakeRect(aspectRatio: photo.size(),insideRect: boundingRect)
       
        return rect.size.height
    }
    
    return 200
}
 

https://ibb.co/J3KdDtG https://ibb.co/JzXZv3V

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)