导入框架pod ‘SDWebImageSwiftUI’, ‘~> 2.0.2’
import SwiftUI
import SDWebImageSwiftUI
struct WebImageExample: View {
let url: URL?
var body: some View {
WebImage(url: url)
.placeholder{
Color.gray
}
.resizable()
.onSuccess(perform: { _, _ , _ in
debugPrint("success")
SDWebImageManager.shared.imageCache.clear(with: .all, completion: nil)
})
.onFailure(perform: { _ in
debugPrint("error")
})
.scaledToFill()
.frame(height: 600)
.frame(width: UIScreen.main.bounds.width - 30)
.clipped()
.cornerRadius(15)
}
}