Created
June 2, 2012 01:50
-
-
Save eliaskg/2856127 to your computer and use it in GitHub Desktop.
UIColor snippet for RubyMotion
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
# Usage: | |
# color('0088cc') | |
# With alpha channel: | |
# color('ff0000', 0.5) | |
def color(color_string, alpha = 1.0) | |
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:alpha) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment