![](/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.