A view that overlays its children, aligning them in both axes.
To indicate loading state, have a private loading bool @State and bind it to Laden’s isAnimating initialzier, default value is true (or animated by default):
To show or hide loading view, have a private show/hide bool @State and modify said loading with .hidden attribute, when toggled:
import SwiftUI
import Laden
struct ContentView: View {
@State private var shouldLoadingView = true
var laden: some View {
Laden.CircleLoadingView(
color: .white, size: CGSize(width: 30, height: 30), strokeLineWidth: 3
)
}
var body: some View {
VStack {
if shouldLoadingView {
laden.hidden()
} else {
laden
}
Button(shouldCircleView ? "Show" : "Hide") {
self.shouldLoadingView.toggle()
}
}
}
}
Customization
To customize loading view color, use color initializer:
Laden.CircleOutlineLoadingView(color: .red)
Available customizations:
/// Loading view protocol that define default configurations.
public protocol LoadingAnimatable: View {
/// Whether this loading view is animating.
var isAnimating: Bool { get }
/// Default color for loading view.
var color: Color { get }
/// The default size for loading view.
var size: CGSize { get set }
/// Default stroke line width for loading bar.
var strokeLineWidth: CGFloat { get }
}
Apps currently using Laden
Clendar - Clendar - universal calendar app. Written in SwiftUI. Available on App Store. MIT License.
Laden
SwiftUI loading indicator view
Installation
This component is built using Swift Package Manager, it is pretty straight forward to use, no command-line needed:
File > Swift Packages > Add Package Dependency...Nextto have Xcode resolve package.Versions, and chooseUp to Next Majoras0.1.0, or checkout the Releases tab for upcoming releases.Finishto integrate package into your Xcode target.Usage
At simplest form:
To show loading view on top on current view, you can embed Laden inside a
ZStack, and put it below your current view:or simply just use
.overlayattribute:To indicate loading state, have a private loading bool
@Stateand bind it to Laden’sisAnimatinginitialzier, default value istrue(or animated by default):To show or hide loading view, have a private show/hide bool
@Stateand modify said loading with.hiddenattribute, when toggled:Customization
To customize loading view color, use
colorinitializer:Available customizations:
Apps currently using Laden
(add yours here)
Acknowledgement
idea 💡
What is Laden, actually?
It’s mean “charge”, in Norwegian ⚡️
Help, feedback or suggestions?
Feel free to open an issue or contact me on Twitter for discussions, news & announcements & other projects. 🚀
I hope you like it! :)