A Swift package providing a customizable toolbar with a progress bar, title, and cancel button for iOS. Easily integrate progress tracking into your app’s UI with animated show/hide functionality.
Add APProgressToolbar to your project via Swift Package Manager:
- In Xcode, go to
File > Add Package Dependency. - Enter the repository URL:
https://github.com/aporat/APProgressToolbar.git - Specify the version or branch (e.g.,
main) and add it to your target.
Or, manually add it to your Package.swift:
dependencies: [
.package(url: "https://github.com/aporat/APProgressToolbar.git", from: "1.0.0")
]Then include it in your target:
.target(name: "YourTarget", dependencies: ["APProgressToolbar"])The toolbar positions itself at the bottom of its superview. Add it once, then drive it with
show(_:) / hide(_:), text, and progressBar.progress.
final class HomeController: UIViewController {
private lazy var loadingToolbar: APProgressToolbar = {
let view = APProgressToolbar()
view.isHidden = true
view.cardBackgroundColor = .systemBackground
view.titleColor = .label
view.progressColors = [.systemBlue, .systemTeal]
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
loadingToolbar.actionDelegate = self
view.addSubview(loadingToolbar)
loadingToolbar.updateLayout()
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil) { [weak self] _ in
self?.loadingToolbar.updateLayout()
}
}
func startLoading() {
loadingToolbar.text = NSLocalizedString("Loading...", comment: "")
loadingToolbar.progressBar.progress = 0
Task { await loadingToolbar.show(true) }
}
func finishLoading() {
loadingToolbar.progressBar.progress = 1
Task { await loadingToolbar.hide(true) } // waits a moment, then slides out
}
}
extension HomeController: APProgressToolbarDelegate {
func didCancelButtonPressed(_ toolbar: APProgressToolbar) {
// stop the work
}
}Set extraBottomOffset to keep the card above content pinned to the bottom, such as an ad banner.