Skip to content

Instantly share code, notes, and snippets.

@bananita
Created November 19, 2015 15:59
Show Gist options
  • Save bananita/46066d908e8ab840a726 to your computer and use it in GitHub Desktop.
Save bananita/46066d908e8ab840a726 to your computer and use it in GitHub Desktop.
random color
func generateRandomColor() -> UIColor {
let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0
let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white
let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment