41
39

More than 5 years have passed since last update.

【Swift】ロード中に使うクルクル(Activity Indicator)を表示する方法

Posted at

デモ

AI.gif

コード

ViewController.swift
import UIKit

class ViewController: UIViewController {

    var ActivityIndicator: UIActivityIndicatorView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // ActivityIndicatorを作成&中央に配置
        ActivityIndicator = UIActivityIndicatorView()
        ActivityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
        ActivityIndicator.center = self.view.center

        // クルクルをストップした時に非表示する
        ActivityIndicator.hidesWhenStopped = true

        // 色を設定
        ActivityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray

        //Viewに追加
        self.view.addSubview(ActivityIndicator)
    }

    @IBAction func start(_ sender: AnyObject) {
        // クルクルスタート
        ActivityIndicator.startAnimating()
    }
    @IBAction func stop(_ sender: AnyObject) {
        // クルクルストップ
        ActivityIndicator.stopAnimating()
    }

}

41
39
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
41
39