Swift - UIActivityIndicatorView

import UIKit
class ViewController: UIViewController{
    var activityIndicator:UIActivityIndicatorView!
    override func viewDidLoad() {
        super.viewDidLoad()
        //设置环形滚动条的样式
        activityIndicator = UIActivityIndicatorView(style: .gray)
        //设置环形滚动条颜色
        activityIndicator.color = UIColor.red
        //设置环形滚动条背景颜色
        activityIndicator.backgroundColor = UIColor.black
        //设置位置
        activityIndicator.center = self.view.center
        //停止转圈时,隐藏(默认为true)
        activityIndicator.hidesWhenStopped = false
        self.view.addSubview(activityIndicator)
        play()
        let Tap = UITapGestureRecognizer(target: self, action: #selector(ViewController.stop))
        Tap.numberOfTapsRequired = 1
        Tap.numberOfTouchesRequired = 1
        self.view.addGestureRecognizer(Tap)
    }
    func play(){
        //开始转动
        activityIndicator.startAnimating()
        //显示当前状态
        print(activityIndicator.isAnimating)
    }
    @objc func stop(){
        //停止转动
        activityIndicator.stopAnimating()
        //显示当前转台
        print(activityIndicator.isAnimating)
    }
 
    
}

你可能感兴趣的:(Swift - UIActivityIndicatorView)