此代码在Swift 2.3中运行良好,但在升级到Swift 3.0时,编译器抱怨模糊使用。
imgProfilePhoto?.setImageWith((URL(string: profileurl)), placeholderImage: UIImage(named: "PatientDefaultProfilePic"), usingActivityIndicatorStyle:UIActivityIndicatorViewStyle.gray)
答案 0 :(得分:2)
Swift 4
import SDWebImage
extension UIImageView {
@objc func setImageWithIndicator(urlStr: String?, placeholder: UIImage) {
guard let _ = urlStr, let url = URL(string: urlStr!) else {
image = placeholder
return
}
sd_setIndicatorStyle(.gray)
sd_addActivityIndicator()
sd_setImage(with: url, placeholderImage: placeholder, options: .refreshCached, completed: nil)
}}
Swift 3
imageView.sd_setImage(with: URL(string: ""), placeholderImage: UIImage(named: ""))
imageView.setShowActivityIndicator(true)
imageView.setIndicatorStyle(.gray)
答案 1 :(得分:1)
Swift等效方法用作从SDWebImage
替换此方法:
imgProfilePhoto?.sd_setImageWithIndicator(with: URL(string: profileurl), placeholderImage: UIImage(named: "PatientDefaultProfilePic"))
答案 2 :(得分:0)
这条线也对我有用:
添加完成处理程序nil。
imgView.setImageWith(imgUrl, completed: nil, usingActivityIndicatorStyle: .gray)