Skip to content

Instantly share code, notes, and snippets.

@aoenth

aoenth/FixedColors.swift

Last active May 27, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.