Skip to content

Instantly share code, notes, and snippets.

@markohlebar
Created November 8, 2016 15:27
Show Gist options
  • Save markohlebar/1cdf3cb8727664a551308fb6ccb7120c to your computer and use it in GitHub Desktop.
Save markohlebar/1cdf3cb8727664a551308fb6ccb7120c to your computer and use it in GitHub Desktop.
extension String {
func hashedColor() -> UIColor {
var hash = self.hash
var rgb = [CGFloat]()
for _ in 0..<3 {
rgb.append(CGFloat(hash % 100) / 100.0)
hash = hash / 100
}
//2, 1, 0 just gives nicer colors 😅
let color = UIColor(red: rgb[2], green: rgb[1], blue: rgb[0], alpha: 1)
var hue: CGFloat = 0
var saturation: CGFloat = 0
var brightness: CGFloat = 0
color.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: nil)
return UIColor(hue: hue, saturation: 0.7, brightness: 0.9, alpha: 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment