I'm working on an app that will start off with four images and eventually more images will be adding onto the screen but for now I'm trying to figure out how I can have the app randomly select one UIImageView every time and set the alpha to 0.7 and the rest to 1.0. I tried doing different ways to make it work but it just doesn't seem good. How can I go about doing this with the code I have already? How would I be able to tell that they found the lower alpha image?
func randomCGFloat() -> CGFloat {
return CGFloat(arc4random()) / CGFloat(UInt32.max)
}
extension UIColor {
static func randomColor() -> UIColor {
let r = randomCGFloat()
let g = randomCGFloat()
let b = randomCGFloat()
return UIColor(red: r, green: g, blue: b, alpha: 1.0)
}
}
class ViewController: UIViewController {
@IBOutlet var image1: UIImageView?
@IBOutlet var image2: UIImageView?
@IBOutlet var image3: UIImageView?
@IBOutlet var image4: UIImageView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let getColor = UIColor.randomColor()
self.image1?.backgroundColor = getColor
self.image2?.backgroundColor = getColor
self.image3?.backgroundColor = getColor
self.image4?.backgroundColor = getColor
}