ButtonProgressBariOS
  • November 11, 2023

Example


  • For LIVE PREVIEW on Appetize in your browser itself, click here.

  • To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements


iOS > 7.0

Installation


ButtonProgressBar-iOS is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod ‘ButtonProgressBar-iOS’

Usage


 

import ButtonProgressBar_iOS

Initialize just like you would any other UIButton:

 

var progressButton = ButtonProgressBar(frame: CGRect)
view.addSubview(progressButton)

Since this is a UIButton subclass, targets and labels can be set in the same way:

progressButton.addTarget(nil, action: #selector(self.tapped), for: .touchUpInside)
progressButton.setTitle(“Download”, for: .normal)

The completion image can be set with;

This image must be set since no default exists.

setCompletionImage(image: UIImage)

Indeterminate loading can be handled with the following functions:

startIndeterminate(withTimePeriod time: TimeInterval)
startIndeterminate(withTimePeriod time: TimeInterval, andTimePadding padding: TimeInterval)

/*
Time Padding is the duration (default 0.5), in seconds, before starting the next cycle.
Time Period is the total time (animation + padding) that 1 cycle of the loading takes.
*/

stopIndeterminate() //Stops the indeterminate loading.

For determinate usage or otherwise, progress can be set with:

setProgress(progress: CGFloat, _ animated: Bool)
/*
Progress ranges from 0.0 to 1.0

If animated is true, linearly animates to progress.
*/

resetProgress() //Set progress to 0.0 unanimated.

Set the progress and background colors:

setBackgroundColor(color: UIColor)
setProgressColor(color: UIColor)

To explicitly show/hide the title / image:

hideTitle(_ hidden: Bool)
hideImage(_ hidden: Bool)

Stop indeterminate loading if active, set progress to 1.0 animated and display completion image if set:

Needs to be called explicitly when loading determinate as well.

triggerCompletion()

GitHub


View Github

#loading #progress #uibutton
YOU MIGHT ALSO LIKE...
🧭 NavigationKit

NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Using Swift Package Manager, add ...

swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation. NavigationStack Installation ...

Stinsen

Simple, powerful and elegant implementation of the Coordinator pattern in SwiftUI. Stinsen is written using 100% SwiftUI which makes it ...

SwiftUI Router

With SwiftUI Router you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes ...

FlowStacks

This package takes SwiftUI's familiar and powerful NavigationStack API and gives it superpowers, allowing you to use the same API not just ...