Swift2.2 使用UIActivityIndicatorView實現轉菊花效果


代碼如下

<pre>
<code>
`

import UIKit

class ViewController: UIViewController
{
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)

override func viewDidLoad()
{
super.viewDidLoad()

    let btnPlay = UIButton()
    btnPlay.frame = CGRectMake(20, 20, 100, 40)
    btnPlay.layer.borderColor = UIColor.blueColor().CGColor
    btnPlay.layer.borderWidth = 2
    btnPlay.setTitle("play", forState: .Normal)
    btnPlay.setTitleColor(UIColor.redColor(), forState: .Normal)
    btnPlay.addTarget(self, action: #selector(ViewController.play), forControlEvents: .TouchUpInside)
    self.view.addSubview(btnPlay)
    
    let btnStop = UIButton()
    btnStop.frame = CGRectMake(20, 100, 100, 40)
    btnStop.layer.borderColor = UIColor.blueColor().CGColor
    btnStop.layer.borderWidth = 2
    btnStop.setTitle("stop", forState: .Normal)
    btnStop.setTitleColor(UIColor.redColor(), forState: .Normal)
    btnStop.addTarget(self, action: #selector(ViewController.stop), forControlEvents: .TouchUpInside)
    self.view.addSubview(btnStop)
    
    activityIndicator.center = self.view.center

    //在view中添加控件activityIndicator
    self.view.addSubview(activityIndicator)

}

//菊花轉動開始
func play()
{
    activityIndicator.startAnimating()
}

//菊花轉動結束
func stop()
{
    activityIndicator.stopAnimating()
}

override func didReceiveMemoryWarning() 
{
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

`
</code>
</pre>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容