2017-10-30 14:52:01 +01:00
2017-10-30 14:34:39 +01:00
2017-09-25 08:54:37 +02:00
2017-10-30 14:52:01 +01:00
2017-10-30 14:52:01 +01:00
2017-10-01 12:35:44 +02:00
2017-10-30 14:34:39 +01:00

GradientLoadingBar

Swift3.0 CI Status Version License Platform

Example

An animated gradient loading bar. Inspired by iOS Style Gradient Progress Bar with Pure CSS/CSS3.

Example

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

Integration

GradientLoadingBar can be added to your project using CocoaPods by adding the following line to your Podfile:

pod 'GradientLoadingBar', '~> 1.0'

How to use

To get started you need to import GradientLoadingBar. To show it, simply call the show() method and after you're done with your operations call hide().

// Create instance
let gradientLoadingBar = GradientLoadingBar()

// Show loading bar
gradientLoadingBar.show()

// Do e.g. server calls etc.

// Hide loading bar
gradientLoadingBar.hide()

Configuration

You can overwrite the default configuration by calling the initializers with the optional parameters height, durations, gradientColors and onView:

let gradientLoadingBar = GradientLoadingBar(
    height: 1.0,
    durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.0)
    gradientColors: [
        UIColor(hexString:"#4cd964").cgColor,
        UIColor(hexString:"#ff2d55").cgColor
    ]
    onView: self.view
)

For custom colors you'll have to pass an array with CGColor values. For creating those colors you can use all initializers for UIColor mentioned here: UIColor+Initializers.swift

For an example using the loading bar on a custom superview (e.g. an UIButton) see the example application. For further cusomization you can also subclass GradientLoadingBar and overwrite the method setupConstraints(). This also shown in the example application.

Custom shared instance

If you don't want to save the instance on a variable and use the singleton instead, you can use the static shared variable. Add the following code to your app delegate didFinishLaunchingWithOptions method:

GradientLoadingBar.shared = GradientLoadingBar(
    height: 3.0,
    durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.00),
    gradientColors: [
        UIColor(hexString:"#4cd964").cgColor,
        UIColor(hexString:"#ff2d55").cgColor
    ]
)

After that you can use GradientLoadingBar.shared to get the instance.

Usage with PromiseKit

Check out my GitHub Gist on how to easily use GradientLoadingBar with PromiseKit.

Author

Felix Mau (contact(@)felix.hamburg)

License

GradientLoadingBar is available under the MIT license. See the LICENSE file for more info.

S
Description
️A customizable animated gradient loading bar.
Readme MIT 201 MiB
Languages
Swift 97.4%
Makefile 2.6%