Swift2.2 使用UIActivityIndicatorView实现转菊花效果


代码如下



`

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.
}

}

`

你可能感兴趣的:(Swift2.2 使用UIActivityIndicatorView实现转菊花效果)