I'm working on a project to generate random images from an array. I'm running into an issue. I will have one button on the screen name "generage shapes". Once the user clicks on this button the "generate shapes" button becomes hidden and 4 buttons display 4 different shapes. I'm having an issue making these 4 buttons display with the image from my array. I tried a switch statement but it doesn't go through. I'm providing my code below. Please let me know if you can help.
Thank you
import UIKit
class ShapesDetailViewController: UIViewController {
var random = arc4random_uniform(4)
@IBOutlet weak var titleBar: UINavigationItem!
@IBOutlet weak var displayMessageLabel: UILabel!
var myImages = [ "diamond.png", "decagon.png", "dodecagon.png", "hectagon.png", "heptagon.png", "octagon.png", "parallelogram.png", "pentagon.png", "rectangle.png", "rightTriangle.png", "square.png", "trapezoid.png", "triangle.png"]
//my image labels
@IBOutlet weak var buttonOne: UIButton!
@IBOutlet weak var buttonTwo: UIButton!
@IBOutlet weak var buttonThree: UIButton!
@IBOutlet weak var buttonFour: UIButton!
@IBOutlet weak var generateImage: UIButton!
override func viewDidLoad() {
self.buttonFour.hidden = true
self.buttonOne.hidden = true
self.buttonThree.hidden = true
self.buttonTwo.hidden = true
displayMessageLabel.hidden = true
}
@IBAction func generateRandomImages(sender: AnyObject) {
displayMessageLabel.hidden = false
buttonOne.hidden = false
switch(random){
case 0: buttonOne.imageView?.image = UIImage(named: "circle.png")
break
case 1: buttonOne.imageView?.image = UIImage(named: "decagon.png")
break
case 2: buttonOne.imageView!.image = UIImage(named: "diamond.png")
break
case 3: buttonOne.imageView!.image = UIImage(named: "hectagon.png")
break
default:
break;
}
generateImage.hidden = true
}
}
Aucun commentaire:
Enregistrer un commentaire