Created
July 23, 2011 21:58
-
-
Save maxluzuriaga/1101932 to your computer and use it in GitHub Desktop.
UIColor Generator From Hex Color Value
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
#!/usr/bin/env ruby | |
# Usage: | |
# uicolorgenerate 0f84d5 | |
# to copy result to clipboard (on a Mac), use: | |
# uicolorgenerate 0f84d5 | pbcopy | |
def main(color_string) | |
case color_string | |
when "fff", "ffffff" | |
return "[UIColor whiteColor]" | |
when "f00", "ff0000" | |
return "[UIColor redColor]" | |
when "0f0", "00ff00" | |
return "[UIColor greenColor]" | |
when "00f", "0000ff" | |
return "[UIColor blueColor]" | |
else | |
red = color_string[0,2].hex | |
green = color_string[2,2].hex | |
blue = color_string[4,2].hex | |
red_percent = red.to_f / 255 | |
green_percent = green.to_f / 255 | |
blue_percent = blue.to_f / 255 | |
return "[UIColor colorWithRed:#{red_percent} green:#{green_percent} blue:#{blue_percent} alpha:1.0]" | |
end | |
end | |
puts main(ARGV[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment