본문 바로가기
Dev/iOS

[SwiftUI] iOS 13에서 ProgressView 사용하기

by steady.dev 2021. 11. 10.

ProgressView는 iOS 14에서 생긴 View 이기 때문에 iOS 13에서는 UIViewRepresentable을 이용해서 구현해서 사용한다.

 

iOS 13용 ProgressView

struct ActivityIndicator: UIViewRepresentable {

    @Binding var isAnimating: Bool
    let style: UIActivityIndicatorView.Style

    func makeUIView(context: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
        return UIActivityIndicatorView(style: style)
    }

    func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicator>) {
        isAnimating ? uiView.startAnimating() : uiView.stopAnimating()
    }
}

 

사용

ActivityIndicator(isAnimating: .constant(true), style: .large)

댓글