Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
leoz committed Sep 10, 2023
1 parent e46d59e commit 4c592a8
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@ This package is based on the [AsyncImage](https://github.com/V8tr/AsyncImage) pr
## Usage

```swift
// Image URLs to load
let posters = [
"https://picsum.photos/800/600?random=1",
"https://picsum.photos/600/800?random=2",
"https://picsum.photos/800/600?random=3",
"https://picsum.photos/600/800?random=4"
].map { URL(string: $0)! }
import CachedImage

let images = (0...20).map {
"https://picsum.photos/800/600?random=\($0)"
}
let imageURLs = images.map {
URL(string: $0)!
}

struct ContentView: View {
var body: some View {
GeometryReader { geometry in
List(posters, id: \.self) { url in
CachedImage(
url: url,
placeholder: { Text("Loading ...") },
image: { Image(platformImage: $0).resizable() }
)
.frame(idealHeight: geometry.size.width / 2 * 3) // 2:3 aspect ratio
}
List(imageURLs, id: \.self) { url in
CachedImage(
url: url,
content: { image in
image
.resizable()
.aspectRatio(contentMode: .fit)
},
placeholder: {
Text("Loading ...")
}
)
.scaledToFit()
}
}
}
Expand Down

0 comments on commit 4c592a8

Please sign in to comment.