An animated gradient loading bar. Inspired by iOS Style Gradient Progress Bar with Pure CSS/CSS3.
To run the example project, clone the repo, and run pod install
from the Example directory first.
GradientLoadingBar can be added to your project using CocoaPods by adding the following line to your Podfile:
pod 'GradientLoadingBar', '~> 1.0'
To get started you need to import GradientLoadingBar
. After that you can use GradientLoadingBar.sharedInstance()
to retrieve an instance to the loading bar. To show it, simply call the show()
method and after you're done call hide()
.
// Show loading bar
GradientLoadingBar.sharedInstance().show()
// Do e.g. server calls etc.
// Hide loading bar
GradientLoadingBar.sharedInstance().hide()
You can overwrite the default configuration by calling the initializers with the optional params height
, durations
and gradientColors
:
let loadingBar = GradientLoadingBar(
height: 1.0,
durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.0)
gradientColors: [
UIColor(hexString:"#4cd964").cgColor,
UIColor(hexString:"#ff2d55").cgColor
]
)
For custom colors you have to pass an array with CGColor
values. For creating those colors you can use all initializers for UIColor
mentioned here: UIColor+Initializers.swift
If you don't want to save the instance on a variable and use the singleton instead, you can use the saveInstance()
method. Add the following code to your app delegate didFinishLaunchingWithOptions
method:
GradientLoadingBar(
height: 3.0,
durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.00),
gradientColors: [
UIColor(hexString:"#4cd964").cgColor,
UIColor(hexString:"#ff2d55").cgColor
]
).saveInstance()
After that you can use GradientLoadingBar.sharedInstance()
as mentioned above.
Check out my GitHub Gist on how to easily use GradientLoadingBar with PromiseKit.
Felix Mau (contact(@)felix.hamburg)
GradientLoadingBar is available under the MIT license. See the LICENSE file for more info.