Last active
May 27, 2020 20:59
-
-
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
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
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