![](/img/trans.png)
[英]Swift 3, SDwebimage - How do you set a button placeholder image on image upload with SDWebImage?
[英]IOS Swift SDWebImage not encoding URL, how do I set an encoder for it?
我正在使用SDWebImage从 URL 加载图像。
以下是我的代码:
if let imageUrl = URL(string: carouselItem.imagesArray[0]) {
itemImageView.sd_setImage (with: imageUrl,placeholderImage: UIImage(named: "ImagePlaceorder"))
} else {
itemImageView.image = UIImage(named: "ImagePlaceorder")
}
图像未加载,因为 URL 中有空格。 我不想对每个单独的 URL 进行编码,我想为图像加载器本身设置一个编码器,以便 SDWebImage 在下载图像之前对 URL 进行编码。
如何将 URL 编码器设置为 SDWebImage?
由于他们没有这种可能性,因此您有几种方法可以解决它。
class ImageVIew: UIImageView {
override open func sd_setImage(with url: URL?, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], completed completedBlock: SDExternalCompletionBlock? = nil) {
// Apply URL encoding
super.sd_setImage(with: newURL, placeholderImage placeholder, options: options, completed: completedBlock)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.