Created
November 15, 2021 15:37
-
-
Save mbernson/187448ae6bfe0dc1cc16259df8fcb0b9 to your computer and use it in GitHub Desktop.
UIActivityIndicatorView in SwiftUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
struct Spinner: UIViewRepresentable { | |
let style: UIActivityIndicatorView.Style | |
@State var animating: Bool = true | |
func makeUIView(context: Context) -> UIActivityIndicatorView { | |
UIActivityIndicatorView(style: style) | |
} | |
func updateUIView(_ uiView: UIActivityIndicatorView, context: Context) { | |
if animating { | |
uiView.startAnimating() | |
} else { | |
uiView.stopAnimating() | |
} | |
} | |
} | |
struct Spinner_Previews: PreviewProvider { | |
static var previews: some View { | |
Group { | |
Spinner(style: .medium) | |
.previewLayout(.sizeThatFits) | |
Spinner(style: .large) | |
.previewLayout(.sizeThatFits) | |
} | |
} | |
} | |
struct Spinner_Library: LibraryContentProvider { | |
@LibraryContentBuilder | |
var views: [LibraryItem] { | |
LibraryItem(Spinner(style: .medium), title: "Spinner medium", category: .control) | |
LibraryItem(Spinner(style: .large), title: "Spinner large", category: .control) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment