Skip to content

Instantly share code, notes, and snippets.

@edwardean
Created August 23, 2018 07:29
Show Gist options
  • Select an option

  • Save edwardean/86b77089781eed794769674ed2867878 to your computer and use it in GitHub Desktop.

Select an option

Save edwardean/86b77089781eed794769674ed2867878 to your computer and use it in GitHub Desktop.
UIColor random color
extension UIColor {
static var radom: UIColor {
#if swift(>=4.2)
return UIColor(red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1), alpha: 1)
#else
return UIColor(red: CGFloat(arc4random_uniform(256) / 255),
green: CGFloat(arc4random_uniform(256) / 255),
blue: CGFloat(arc4random_uniform(256) / 255), alpha: 1)
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment