Created
November 8, 2016 15:27
-
-
Save markohlebar/1cdf3cb8727664a551308fb6ccb7120c to your computer and use it in GitHub Desktop.
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 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