微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决将图像高度从图像 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 举报,一经查实,本站将立刻删除。