SwiftUI异步图片加载AsyncImage


1个月前 114次点击 来自 移动端

标签: SwiftUI

iOS15后可用SwiftUI异步图片加载AsyncImage,iOS14之前还是使用Kingfisher异步加载,又多了一个不向下兼容开发的理由(懒)

private let tesla = "https://www.carshowroom.com.au/media/21484061/2020-tesla-roadster-01.jpg"

AsyncImage(url: URL(string: tesla)) { image in
    // 1
    image
        .resizable()
        .scaledToFit()
} placeholder: {
    ZStack {
        // 2
        Color.gray
        // 3
        VStack(spacing: 20) {
            // 4
            ProgressView()
            // 5
            Text("Loading...")
                .foregroundColor(Color.white)
        }
    }
}
// 6
.frame(width: 400, height: 300)

Made with in Shangrao,China By Devler.

Copyright © Devler 2012 - 2022

赣ICP备19009883号-1

Top ↑