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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容