Skip to content

Latest commit

 

History

History
60 lines (46 loc) · 1.38 KB

File metadata and controls

60 lines (46 loc) · 1.38 KB

AsyncResizableImage

A SwiftUI view that asynchronously downloads, cache and optionally resizes an image from a URL

Features

  • 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

Installation

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"
    ]
)

Usage

import AsyncResizableImage
import SwiftUI

struct ContentView: View {
    var body: some View {
        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

License

MIT License. See LICENSE for details.