如何在Swift 4.2中使用SDWebImage来使用headerView完成块?

问题描述 投票:0回答:1

我试图想出一种方法将通过headerView上的SDWebImage加载的图像推送到可以在headerView中查看图像的视图。

我尝试了这个闭包方法sd_setImageWithURL(NSURL(string:urlString),完成了:{(image,error,cacheType,url)in

但我收到此错误//'UIView'类型的值?没有会员'sd_setImage'

//发生错误的代码行

self.headerView.sd_setImage(with:URL(string:flowerImageURL),completed:{(image,error,cache,url)in

swift4.2
1个回答
1
投票

SDWebImage用于在UIImageView,UIButton,MKAnnotationView中显示图像,而不用于UIView。它在README.md中清楚地描述

https://github.com/SDWebImage/SDWebImage

此库提供具有缓存支持的异步映像下载程序。为方便起见,我们为UI元素添加了类别,如UIImageView,UIButton,MKAnnotationView。 UIImageView,UIButton,MKAnnotationView的类别添加Web图像和缓存管理

因此,您可以在headerView中创建imageView并使用该imageview中的“sd_setImage”

imageView.sd_setImage(with: URL(string: urlString), placeholderImage: UIImage(named: "placeholder.png"))

链接到:HowToUse

© www.soinside.com 2019 - 2024. All rights reserved.