diff --git a/README.md b/README.md index 0df10dc..565dec6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Swift Package Manager compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) -Async image loading with cache for SwiftUI. +Async image loading with progress and cache for SwiftUI. ## Screenshots ![](./demo.png) @@ -10,7 +10,8 @@ Async image loading with cache for SwiftUI. ## Installation ### [Swift Package Manager](https://swift.org/package-manager/) -Going to Xcode `File` > `Add Packages...` and add the repository by giving the URL `https://github.com/bullinnyc/CachedAsyncImage` +Going to Xcode `File` > `Add Packages...` and add the repository by giving the URL +`https://github.com/bullinnyc/CachedAsyncImage` Enjoy! ## Usage @@ -19,7 +20,7 @@ Enjoy! import CachedAsyncImage ``` -### Create any view for placeholder and customize image +### Quick start **Note:** `placeholder` is an optional parameter. ```swift @@ -28,7 +29,7 @@ let exampleUrl = "https://example.com/image.jpg" CachedAsyncImage( url: exampleUrl, placeholder: { - // Create any view for placeholder. + // Create any view for placeholder (optional). ZStack { Color.yellow ProgressView() @@ -43,6 +44,53 @@ CachedAsyncImage( ) ``` +### Use it to the fullest +**Note:** `placeholder` and `error` is an optional parameters. + +```swift +let exampleUrl = "https://example.com/image.jpg" + +CachedAsyncImage( + url: exampleUrl, + placeholder: { progress in + // Create any view for placeholder (optional). + ZStack { + Color.yellow + + ProgressView() { + VStack { + Text("Downloading...") + Text("\(progress) %") + } + } + } + }, + image: { + // Customize image. + Image(uiImage: $0) + .resizable() + .scaledToFill() + }, + error: { error in + // Create any view for error (optional). + ZStack { + Color.yellow + + VStack { + Text("Error:") + .bold() + + Text(error) + } + .font(.footnote) + .multilineTextAlignment(.center) + .foregroundColor(.red) + .frame(width: 120) + } + } +) +``` + ### Set image cache limit (optional) **Note:** The default value is `0`, e.g. is no count limit and is no total cost limit.