Contents

aporat/approgresstoolbar

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.

Installation

Swift Package Manager

Add APProgressToolbar to your project via Swift Package Manager:

  1. In Xcode, go to File > Add Package Dependency.
  2. Enter the repository URL:

`` https://github.com/aporat/APProgressToolbar.git ``

  1. 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"])

Usage

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.

Package Metadata

Repository: aporat/approgresstoolbar

Default branch: main

README: README.md