Last active
July 5, 2016 13:24
-
-
Save klein-artur/df56b8ecdada5487c6f7 to your computer and use it in GitHub Desktop.
get a random UIColor in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getRandomColor(minVal: Int = 0, maxVal: Int = 255) -> UIColor { | |
// get random values between the min value (0) and max value (255): | |
let randomRed: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
let randomGreen: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
let randomBlue: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
return UIColor(red: CGFloat(Float(randomRed) / Float(255)), green: CGFloat(Float(randomGreen) / Float(255)), blue: CGFloat(Float(randomBlue) / Float(255)), alpha: 1.0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment