vendredi 31 juillet 2015

how to randomize my image view?

i want every time when i hit the button next a random image different of the current

this is the code that i use but sometime the image didn't update:

    @IBAction func nextBarButton(sender: UIBarButtonItem) {


    var image1 = UIImage(named: "RedBalloon1.jpg")
    var image2 = UIImage(named: "RedBalloon2.jpg")
    var image3 = UIImage(named: "RedBalloon3.jpg")
    var image4 = UIImage(named: "RedBalloon4.jpg")

    var images = [image1, image2, image3, image4]
    var indexPath = Int(arc4random_uniform(UInt32(images.count)))
    currentIndex = indexPath
    if currentIndex == indexPath {
        indexPath = Int(arc4random_uniform(UInt32(images.count)))
    }

    self.imageView.image = images[indexPath]
    self.balloonLabel.text = "\(count++) Balloon"


}




Aucun commentaire:

Enregistrer un commentaire