Skip to content

Instantly share code, notes, and snippets.

@eliaskg
Created June 2, 2012 01:50
Show Gist options
  • Save eliaskg/2856127 to your computer and use it in GitHub Desktop.
Save eliaskg/2856127 to your computer and use it in GitHub Desktop.
UIColor snippet for RubyMotion
# 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