Fullscreen activityIndicator with Swift 2.3

fullscreen activityIndicator with semi-transparent background
fullscreen activityIndicator with semi-transparent background

Here is a code snippet for those who have been looking for simple solution on how to make fullscreen activityIndicator with Swift.

First, inside of yourt UIViewController create variable to hold activityIndicator:

var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()

Then add this two methods to start and stop activityIndicator when your application required:

    func startActivityIndicator() {
        let screenSize: CGRect = UIScreen.mainScreen().bounds
        activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
        activityIndicator.frame = CGRectMake(0, 0, screenSize.width, screenSize.height)
        activityIndicator.center = self.view.center
        activityIndicator.hidesWhenStopped = true
        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.White
        // Change background color and alpha channel here
        activityIndicator.backgroundColor = UIColor.blackColor()
        activityIndicator.clipsToBounds = true
        activityIndicator.alpha = 0.5
    func stopActivityIndicator() {

Hope it helps!

3,101 total views, 5 views today

Leave a Reply

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