02-ContentView-5.swift 876 B

123456789101112131415161718192021222324252627
  1. import SwiftUI
  2. import Kingfisher
  3. struct ContentView: View {
  4. func url(at index: Int) -> URL? {
  5. let urlPrefix = "https://raw.githubusercontent.com/onevcat/Kingfisher-TestImages/master/DemoAppImage/Loading/kingfisher"
  6. return URL(string: "\(urlPrefix)-\(index + 1).jpg")
  7. }
  8. var body: some View {
  9. List {
  10. ForEach(0 ..< 10) { i in
  11. HStack {
  12. KFImage(url(at: i))
  13. .resizable()
  14. .roundCorner(
  15. radius: .widthFraction(0.5),
  16. roundingCorners: [.topLeft, .bottomRight]
  17. )
  18. .serialize(as: .PNG)
  19. .frame(width: 64, height: 64)
  20. Text("Index \(i)")
  21. }
  22. }
  23. }.listStyle(.plain)
  24. }
  25. }