Created
February 11, 2017 17:17
-
-
Save rcharlton/f3e3caf7da02cab1c11fb2fe1b227ef2 to your computer and use it in GitHub Desktop.
Random UIColor values
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
extension UIColor { | |
class func random() -> UIColor { | |
return UIColor( | |
hue: CGFloat.random(min: 0.0, max: 1.0), | |
saturation: CGFloat.random(min: 0.3, max: 0.6), | |
brightness: CGFloat.random(min: 0.7, max: 1.0), | |
alpha: 1.0) | |
} | |
} | |
private extension CGFloat { | |
static func random(min: CGFloat, max: CGFloat) -> CGFloat { | |
let number = Double(arc4random() % UINT32_MAX) / Double(UINT32_MAX) | |
return min + CGFloat(Double(max - min) * number) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment