SwiftUI URLImage, AsyncImage

황인성·2025년 2월 28일

iOS

목록 보기
24/24
post-thumbnail

URLImage

  • ios15보다 낮을때 사용

AsyncImage

  • ios15 이상 일때 사용
import SwiftUI
import URLImage

struct TestView: View {
    var body: some View {
        if #available(iOS 15.0, *) {
            
            AsyncImage(url: URL(string: "https://velog.velcdn.com/images/fiddich/post/fecaabfe-eae6-4da0-92de-05a6156bc288/image.png")) { image in
                image
                    .resizable()
                    .aspectRatio(contentMode: .fill)
            } placeholder: {
                ProgressView()
            }
            .frame(width: 100, height: 100)
            
        }
        else {
            
            URLImage(URL(string: "https://velog.velcdn.com/images/fiddich/post/fecaabfe-eae6-4da0-92de-05a6156bc288/image.png")!) {
                EmptyView()
            } inProgress: { progress in
                ProgressView()
            } failure: { error, retry in
                VStack {
                    Text(error.localizedDescription)
                    Button("Retry", action: retry)
                }
            } content: { image in
                image
                    .resizable()
                    .aspectRatio(contentMode: .fill)
            }
            .frame(width: 100, height: 100)
            
        }
    }
}
profile
iOS, Spring developer

0개의 댓글