Skip to content

Instantly share code, notes, and snippets.

@aoenth
Last active May 27, 2020 20:59
Show Gist options
  • Save aoenth/d88c052ca4d145e4650b20b1be0b57d1 to your computer and use it in GitHub Desktop.
Save aoenth/d88c052ca4d145e4650b20b1be0b57d1 to your computer and use it in GitHub Desktop.
Return a color based on percentage. 0% is Red and 100% is Green
static func colorForPercent(_ percentage: Double) -> UIColor {
switch percentage {
case 0..<0.33:
return UIColor(hex: 0xE02020)
case 0.33..<0.66:
return UIColor(hex: 0xFA6400)
case 0.66..<1:
return UIColor(hex: 0xF7B500)
case 1:
return UIColor(hex: 0x6DD400)
default:
fatalError("Bad Input: percentage must satisfy 0 <= percentage <= 1")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment