A SwiftUI view that asynchronously downloads, cache and optionally resizes an image from a URL
- Asynchronously fetches an image from a URL
- Optionally resizes the image to a given size
- Caches the downloaded image
- Fully customizable placeholder and image rendering
Add the following to your Package.swift dependencies:
.package(url:"https://github.com/AnthonyBY/AsyncResizableImage.git", from:"1.0.0")Then add "AsyncResizableImage" to your target dependencies:
.target(
name:"YourTarget",
dependencies:["AsyncResizableImage"])import AsyncResizableImage
import SwiftUI
structContentView:View{varbody:someView{AsyncResizableImage(
url:URL(string:"https://example.com/image.jpg"),
targetSize:CGSize(width:200, height:200),
content:{ image in
image
.resizable().aspectRatio(contentMode:.fit)},
placeholder:{ProgressView()})}}Or you can just copy the file AsyncResizableImage to your project.
Enjoy
MIT License. See LICENSE for details.