Skip to content

Instantly share code, notes, and snippets.

@lindskogen
Created June 12, 2019 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindskogen/a5b10a48f208256631dee78cba99dd7c to your computer and use it in GitHub Desktop.
Save lindskogen/a5b10a48f208256631dee78cba99dd7c to your computer and use it in GitHub Desktop.
SwiftUI Wrapper for UIActivityIndicator
import SwiftUI
import UIKit
struct ActivityIndicator : UIViewRepresentable {
var animating: Bool
var hidesWhenStopped = true
var style: UIActivityIndicatorView.Style = UIActivityIndicatorView.Style.medium
func makeUIView(context: Context) -> UIActivityIndicatorView {
let control = UIActivityIndicatorView()
updateValues(for: control)
return control
}
func updateValues(for uiView: UIActivityIndicatorView) {
uiView.style = style
uiView.hidesWhenStopped = hidesWhenStopped
if animating {
uiView.startAnimating()
} else {
uiView.stopAnimating()
}
}
func updateUIView(_ uiView: UIActivityIndicatorView, context: Context) {
updateValues(for: uiView)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment