Thursday, July 30, 2015

UIActivityIndicatorView - Show an Activity Indicator Programmatically

Update: July 8, 2017 (Swift 3.1 + Xcode 8.3.3)
Original Post: July 30, 2015 (Swift 1 + Xcode 6.4)

Complete the code as below:

Update: July 8, 2017 (Swift 3.1 + Xcode 8.3.3)

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myActivityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
        myActivityIndicator.center = view.center
        myActivityIndicator.startAnimating()
        view.addSubview(myActivityIndicator)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}

Original Post: July 30, 2015 (Swift 1 + Xcode 6.4)

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        var myActivityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
        myActivityIndicator.center = view.center
        myActivityIndicator.startAnimating()
        view.addSubview(myActivityIndicator)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}

The result:

1 comment: