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.
  let customLoader = UIImageView(frame: frame)
  • Add images which will be used for the animation using an array.
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 
  • Set the duration of the single animation cycle.
customLoader.animationDuration = 0.5;
  • Add customLoader as a subview to your view in which you want to show loader.
view.addSubview(customLoader)
  • Start the loader animation.
customLoader.startAnimating()

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

  • Stop the loader animation.
customLoader.stopAnimating()
  • Remove loader from super view.
customLoader.removeFromSuperview()

Wow! You have created you own custom loader…

FOUND THIS USEFUL? SHARE IT

Leave a comment -