Answers for "swiftui activity indicator"

1

swift activity indicator

//https://medium.com/swlh/how-to-give-your-viewcontroller-an-activity-indicator-4c3bfd84893e
//Controller Class
var activityIndicator = UIActivityIndicatorView(style: .Large)
//inside ViewDidLoad
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(activityIndicator)
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

//now use anywhere to start and stop animation
activityIndicator.startAnimating()

//and
activityIndicator.stopAnimating()
Posted by: Guest on February-26-2021
0

activity indicator swiftui

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()
    }
}

//Usage...
ActivityIndicator(isAnimating: .constant(true), style: .large)
Posted by: Guest on March-02-2020

Code answers related to "swiftui activity indicator"

Code answers related to "Swift"

Browse Popular Code Answers by Language