Skip to content

Instantly share code, notes, and snippets.

@rcharlton
Created February 11, 2017 17:17
Show Gist options
  • Save rcharlton/f3e3caf7da02cab1c11fb2fe1b227ef2 to your computer and use it in GitHub Desktop.
Save rcharlton/f3e3caf7da02cab1c11fb2fe1b227ef2 to your computer and use it in GitHub Desktop.
Random UIColor values
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