Home

Awesome

Carthage compatible

FillableLoaders

Completely customizable progress based loaders drawn using custom CGPaths written in Swift

<p align="center"> <img src="Images/waves.gif" height="120px"/> </p> <p align="center"> Waves </p> <p align="center"> <img src="Images/plain.gif" height="120px"/> </p> <p align="center"> Plain </p> <p align="center"> <img src="Images/spike.gif" height="120px"/> </p> <p align="center"> Spike </p> <p align="center"> <img src="Images/rounded.gif" height="120px"/> </p> <p align="center"> Rounded </p>

Demo:

<p align="center"> <img src="Images/progress.gif" height="200px"/> </p> <p align="center"> <img src="Images/demo.png" height="300px"/> </p>

Changelog:

Quick Start:

- Progress based behaviour

Therea are only 2 necessary things to make the progress based loader work:

- Creation

There are four main methods to create the loaders:

showProgressBasedLoaderWithPath(path:), createProgressBasedLoaderWithPath(path:),showLoaderWithPath(path:) and createLoaderWithPath(path:)

showLoaderWithPath(path:) or showProgressBasedLoaderWithPath(path:) are going to call the create one, and after it, are going to call the showLoader() method.

So, it is just a helper method to do everything at once.

If you want to create the loader, and not show it at the same moment, you can use createProgressBasedLoaderWithPath(path:) or createLoaderWithPath(path:) to create it, and when you want to show it, just call showLoader()

Sample code:

//PROGRESS BASED:
		
var loader = WavesLoader.createProgressBasedLoaderWithPath(path)
loader.loaderColor = UIColor.redColor()
        ...
//Do other stuff
        ...
loader.showLoader()
		
//BASIC

var loader = WavesLoader.createLoaderWithPath(path)
loader.loaderColor = UIColor.redColor()
        ...
//Do other stuff
        ...
loader.showLoader()

- Showing loader in desired view:

All the methods wave the variant version where you can pass it the view in which you want to add the loader:

- Deletion:

Just call the method removeLoader() and the loader will disappear and will also be removed from its superview.

Sample code:

loader.removeLoader()

Customization:

Apart from being able to customize the loader shape, you can also customize other properties of the loader. Take a look at the list:

Extra property for Spikes and Rounded loaders:

Installation:

• CocoaPods

use_frameworks!

pod 'FillableLoaders', '~>1.3.0'

• Carthage

github "poolqf/FillableLoaders" ~> "1.3.0"

• Manually

To manually add FillableLoaders to your project you just need to copy the Source folder files.

How to create my own CGPath?

:warning: The CGPath bounds cannot exceed the bounds of the loaderView:

• Manually

let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, 0, height/2)
CGPathAddLineToPoint(path, nil, width + 100, height/2)
CGPathAddLineToPoint(path, nil, width + 100, height*2)
CGPathAddLineToPoint(path, nil, 0, height*2)
CGPathCloseSubpath(path)
return path

• PaintCode

PaintCode is a realy powerful Mac app that can do a lot of things. You can just draw things, and it will automagically create the code for you

In this case we can use it to create BezierPaths, and extract from there the CGPath.

In the case of drawing a star, it is going to give us this code:

//// Star Drawing
var starPath = UIBezierPath()
starPath.moveToPoint(CGPointMake(180, 25))
starPath.addLineToPoint(CGPointMake(195.16, 43.53))
starPath.addLineToPoint(CGPointMake(220.9, 49.88))
starPath.addLineToPoint(CGPointMake(204.54, 67.67))
starPath.addLineToPoint(CGPointMake(205.27, 90.12))
starPath.addLineToPoint(CGPointMake(180, 82.6))
starPath.addLineToPoint(CGPointMake(154.73, 90.12))
starPath.addLineToPoint(CGPointMake(155.46, 67.67))
starPath.addLineToPoint(CGPointMake(139.1, 49.88))
starPath.addLineToPoint(CGPointMake(164.84, 43.53))
starPath.closePath()
UIColor.grayColor().setFill()
starPath.fill()

The only thing we have to do here is extract the CGPath from the UIBezierPath like so:

let myPath = starPath.CGPath
var myLoader = WavesLoader.showProgressBasedLoaderWithPath(myPath)

• SVG + PaintCode

A feature that I LOVE from PaintCode is that you can import an .svg file, and it is going to create the code to create its BezierPath. Completely awesome.

That's how I did the Github and Twitter logos, for example.

Technical details:

Licenses

All source code is licensed under the MIT License.

If you use it, i'll be happy to know about it.

Pol Quintana - @poolqf