项目作者: V8tr

项目描述 :
Asynchronous Image Loading from URL in SwiftUI
高级语言: Swift
项目地址: git://github.com/V8tr/AsyncImage.git
创建时间: 2020-02-13T15:46:13Z
项目社区:https://github.com/V8tr/AsyncImage

开源协议:The Unlicense

下载


Article related to this project


AsyncImage

The project demonstrates how to load images asynchronously in SwiftUI.

Usage:

  1. // Image URLs to load
  2. let posters = [
  3. "https://image.tmdb.org/t/p/original/pThyQovXQrw2m0s9x82twj48Jq4.jpg",
  4. "https://image.tmdb.org/t/p/original/vqzNJRH4YyquRiWxCCOH0aXggHI.jpg",
  5. "https://image.tmdb.org/t/p/original/6ApDtO7xaWAfPqfi2IARXIzj8QS.jpg",
  6. "https://image.tmdb.org/t/p/original/7GsM4mtM0worCtIVeiQt28HieeN.jpg"
  7. ].map { URL(string: $0)! }
  8. struct ContentView: View {
  9. var body: some View {
  10. List(posters, id: \.self) { url in
  11. AsyncImage(
  12. url: url,
  13. placeholder: { Text("Loading ...") },
  14. image: { Image(uiImage: $0).resizable() }
  15. )
  16. .frame(idealHeight: UIScreen.main.bounds.width / 2 * 3) // 2:3 aspect ratio
  17. }
  18. }
  19. }

Result:


How to load image from URL asynchronously in SwiftUI