A customizable, animated loading overlay for SwiftUI applications.
- Easy to integrate with existing SwiftUI projects
- Customizable spinner color, size, message, background, and more
- Works across iOS, macOS, tvOS, and watchOS
- Fade in/out animation
- Can be used as a view or a view modifier
- iOS 13.0+
- macOS 10.15+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
- Swift 5.1+
You can add LoadingView to your project using Swift Package Manager. In Xcode:
- Go to File > Swift Packages > Add Package Dependency
- Enter the repository URL:
https://github.com/SeikoLai/SwiftUI_LodingView.git - Select the version you want to use
There are two main ways to use the LoadingView in your SwiftUI projects:
You can use LoadingView directly in your SwiftUI views:
import SwiftUI
import LoadingView
struct ContentView: View {
@State private var isLoading = false
var body: some View {
ZStack {
// Your main content here
Button("Start Loading") {
isLoading = true
// Simulate some work
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
isLoading = false
}
}
LoadingView(isPresented: $isLoading, message: "Processing...")
}
}
}You can also use the .loadingView() modifier on any view:
import SwiftUI
import LoadingView
struct ContentView: View {
@State private var isLoading = false
var body: some View {
Button("Start Loading") {
isLoading = true
// Simulate some work
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
isLoading = false
}
}
.loadingView($isLoading, message: "Please wait...")
}
}Both LoadingView and the .loadingView() modifier accept several parameters for customization:
isPresented: Binding to control the visibility of the loading viewspinnerColor: The color of the spinner (default: white)diameter: The diameter of the spinner (default: 30)message: The message to display below the loading indicator (default: "Loading...")messageColor: The color of the message text (default: white)backgroundColor: The background color of the loading view (default: semi-transparent black)cornerRadius: The corner radius of the loading view container (default: 10)
Example with custom options:
LoadingView(
isPresented: $isLoading,
spinnerColor: .blue,
diameter: 40,
message: "Fetching data...",
messageColor: .white,
backgroundColor: Color.black.opacity(0.7),
cornerRadius: 20
)Or using the modifier:
.loadingView(
$isLoading,
spinnerColor: .blue,
diameter: 40,
message: "Fetching data...",
messageColor: .white,
backgroundColor: Color.black.opacity(0.7),
cornerRadius: 20
)The main view struct that displays the loading overlay.
A view modifier that adds a loading overlay to any view.
A customizable spinning loading indicator.
Adds the loadingView() method to easily apply the loading overlay to any view.
For detailed API documentation, please refer to the inline documentation in the source files.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions to LoadingView are welcome! Please feel free to submit a Pull Request.