Create Custom Loader Using Images in iOS App

26 / Jan / 2016 by Ashu Baweja 0 comments

Ever wanted to have your own custom loader view instead of iOS default activity indicator?ajax-loaderseubagif
Is it difficult to create your own custom loader ???

download
No, it’s not. You can easily create custom loader using UIImageView animationImages property.You just need images using which you will create your own loader.

So here is the way to create loader :

  • Initialize the object of UIImageView.

[code language=”objc”]
let customLoader = UIImageView(frame: frame)
[/code]

  • Add images which will be used for the animation using an array.

[code language=”objc”]
let imagesArray = [UIImage(named: "1.png")!,
UIImage(named: "2.png")!,
UIImage(named: "3.png")!,
UIImage(named: "4.png")!,
UIImage(named: "5.png")! ]

customLoader.animationImages = imagesArray
[/code]

  • Set the duration of the single animation cycle.

[code language=”objc”]
customLoader.animationDuration = 0.5;
[/code]

  • Add customLoader as a subview to your view in which you want to show loader.

[code language=”objc”]
view.addSubview(customLoader)
[/code]

  • Start the loader animation.

[code language=”objc”]
customLoader.startAnimating()
[/code]

To stop loader you just need to write the following code:

  • Stop the loader animation.

[code language=”objc”]
customLoader.stopAnimating()
[/code]

  • Remove loader from super view.

[code language=”objc”]
customLoader.removeFromSuperview()
[/code]

Wow! You have created you own custom loader…

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *