ProgressBar

public class ProgressBar : NSObject

An animatable and customizable progress bar.

  • Initializes the progress bar instance and (optionally) based on the given progress bar’s track configuration(s) and bar configuration.

    trackColour

    The number of elements in this array will determine whether the progress bar’s track, would be a solid colour (single element), or gradient colours (more than 1 element).

    barColour

    The number of elements in this array will determine whether the progress bar’s bar, would be a solid colour (single element), or gradient colours (more than 1 element).

    configurations

    The PBConfiguration takes in 2 keys which are .track and .bar. Both represents the progress bar’s track and bar elements, respectively.

    The PBConfiguration.track accepts an Array of PBTrackConfigurations which will:

    • Configure the progress bar’s track display.
    • Determine the number of progress bar that will be displayed. (1 track configuration represents 1 progress bar track)

    On the other hand, the PBConfiguration.bar accepts an object of type PBBarConfiguration which will configure the progress bar’s bar display.

    Similar with the progress bar’s track configurations, the progress bar’s bar configuration can also be customized, or used with default values.

    Declaration

    Swift

    public init(trackColour: [UIColor], barColour: [UIColor], configurations: [PBConfigurations : Any] = [:])

    Parameters

    trackColour

    An array of the progress bar’s track UIColor.

    barColour

    An array of the progress bar’s bar UIColor.

    configurations

    The PBConfiguration that takes in the configurations for the progress bar’s track and bar. (optional)

  • Sets up the progress bar within the given container view.

    This method should only be called ONCE, and only in viewDidLayoutSubviews to ensure the container has already been laid out correctly by AutoLayout.

    Declaration

    Swift

    public func setupProgressBar(in container: UIView)

    Parameters

    container

    The container view to initialize the progress bar in.

  • Animates the progress bar from 0 until the given percentage value (in decimals) of the total width of the progress bar container view. Animation duration defaults to 0.75.

    This method should only be called after calling setupProgressBar(in:) to ensure the progress bar is already initialized.

    Declaration

    Swift

    public func setProgressBarValue(to value: CGFloat, duration: Double = 0.75)

    Parameters

    value

    The percentage (in decimals) for the progress bar’s width to expand to, within a minimum value of 0, and a maximum value of 1.

    duration

    The animation duration to animate the progress bar. (optional)