2016年7月28日 星期四

[swift] imageView Attributes

There are six pictures .


class ViewController: UIViewController {
    @IBOutlet weak var imageShow: UIImageView!

    var arrImg = ["img01","img02","img03","img04","img05","img06"]
    var images:Array<UIImage> = []
    var p:Int = 0
    var count:Int = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        imageShow.image = UIImage(named: arrImg[p])
        count = arrImg.count
        for key in arrImg {
            images.append(UIImage(named: key)!)
        }
        imageShow.animationImages = images
        imageShow.animationDuration = NSTimeInterval(count * 1)
        imageShow.animationRepeatCount = 0
        
        // Do any additional setup after loading the view, typically from a nib.
    }

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

    @IBAction func prevClick(sender: UIButton) {
        p = p - 1
        if p < 0 {
            p = count - 1
        }
        imageShow.image = UIImage(named: arrImg[p])
    }

    @IBAction func nextClick(sender: UIButton) {
        p = p + 1
        if p == count {
            p = 0
        }
        imageShow.image = UIImage(named: arrImg[p])
    }
    @IBAction func playClick(sender: UIButton) {
        imageShow.startAnimating()
    }
    @IBAction func stopClick(sender: UIButton) {
        imageShow.stopAnimating()
    }
    @IBAction func borderClick(sender: UIButton) {
        imageShow.layer.borderColorUIColor.blueColor().CGColor
        imageShow.layer.borderWidth = 3
    }
    @IBAction func roundClick(sender: UIButton) {
        imageShow.layer.cornerRadius = 10.0
        imageShow.layer.masksToBounds = true
    }
    @IBAction func shadowClick(sender: UIButton) {
        imageShow.layer.shadowColor = UIColor.blackColor().CGColor
        imageShow.layer.shadowOffset = CGSizeMake(10.0, 10.0)
        imageShow.layer.shadowOpacity = 0.8
        imageShow.layer.shadowRadius = 5
    }
    @IBAction func normalClick(sender: UIButton) {
        imageShow.layer.borderWidth = 0
        imageShow.layer.cornerRadius = 0
        imageShow.layer.masksToBounds = false
        imageShow.layer.shadowOpacity = 0
    }

}

沒有留言:

張貼留言