how to apply Music Radio loading in UIAlertController?

98 views Asked by At

I want to create this loading style in my project,i really dont know how.I am really a beginner to swift ui components.I want to add this loading style in my alert view and after getting the results i want to dismiss.So,i want to know about how to make it and add to the alert view to make present and dismiss,Any help please?

enter image description here

1

There are 1 answers

6
Dharmesh Kheni On BEST ANSWER

First of all you can not do it into default alert view but you can create a custom view and achieve this.

For that you need one circle image and you can add that into Image view and add one label which has text Loading.. add both into View like shown into below image:

enter image description here

After that connect outlet for all of this. and you can show that view as per your need and when you show this view you can rotate image with this code:

func rotateViewLayer() {
    let rotateView = CABasicAnimation()

    rotateView.fromValue = 0.degreesToRadian
    rotateView.toValue = 360.degreesToRadian
    rotateView.duration = 1
    rotateView.repeatCount = Float.infinity
    rotateView.removedOnCompletion = false
    rotateView.fillMode = kCAFillModeForwards
    rotateView.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
    imageView.layer.addAnimation(rotateView, forKey: "transform.rotation.z")
}

And you will need this extension:

extension Int {
var degreesToRadian : CGFloat {
    return CGFloat(self) * CGFloat(M_PI) / 180.0
    }
}

and when you hide this view you can remove animation from imageview with this:

imageView.layer.removeAllAnimations()

And you can check result HERE.

You can use THIS Amazing library too.

And HERE is complete working project.

Hope this will help you.