Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.93 KB

18.UI基础之UIActivityIndicatorView.md

File metadata and controls

59 lines (45 loc) · 1.93 KB

18.UI基础之UIActivityIndicatorView

活动指示器,就是Android中的loading框。UIActivityIndicatorView继承自UIView。

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let indicatorView = UIActivityIndicatorView(style: .white)
        indicatorView.frame = CGRect(x: 0, y: 100, width: 50, height: 50)
        view.addSubview(indicatorView)
        indicatorView.backgroundColor = UIColor.green
        
        let gray = UIActivityIndicatorView(style: .gray)
        gray.frame = CGRect(x: 60, y: 100, width: 50, height: 50)
        view.addSubview(gray)
        
        let whiteLarge = UIActivityIndicatorView(style: .whiteLarge)
        whiteLarge.frame = CGRect(x: 120, y: 100, width: 100, height: 100)
        whiteLarge.backgroundColor = UIColor.red
        view.addSubview(whiteLarge)
        // 必须调用startAnimationg才会显示
        indicatorView.startAnimating()
        gray.startAnimating()
        whiteLarge.startAnimating()
    }
}

判断和停止

// 判断是否正在执行
let isAnimating = indicatorView.isAnimating
// 停止
indicatorView.stopAnimating()
// 当活动指示器停止,是否隐藏
indicatorView.hidesWhenStopped = true
// 设置边框等
indicatorView.masksToBounds = true
indicatorView.layer.borderWidth = 1.0
indicatorView.layer.borderColor = UIColor.green