SwiftUI组件-AsyncImage
import SwiftUIstruct AsyncImageBootcamp: View {let url = URL(string: "https://picsum.photos/200")var body: some View {/// Mark - iOS15 以后才有的方法ScrollView {AsyncImage(url: url, content: { returnImage inreturnImage.resizable().scaledToFit().frame(width: 100, height: 100).cornerRadius(10)}, placeholder: {ProgressView()})AsyncImage(url: url, scale: 1.0)AsyncImage(url: url) { phase inswitch phase {case .empty:ProgressView()case .success(let returnImage):returnImage.resizable().scaledToFit().frame(width: 100, height: 100).cornerRadius(10)case .failure(let error):Image(systemName: "questionmark")@unknown default:Image(systemName: "questionmark")}}}}
}#Preview {AsyncImageBootcamp()
}
效果如下: