Created
June 4, 2012 13:37
-
-
Save Cosmo/2868435 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def color_with(value=nil, options={}) | |
if options.is_a?(Numeric) | |
alpha = options.to_f | |
else | |
alpha = options.delete(:alpha) || 1 | |
end | |
if value | |
if (value.is_a?(String) && value[0] == "#") | |
value = value.gsub("#", "").to_i(16) | |
end | |
if value.is_a?(Fixnum) | |
red = ((value & 0xFF0000) >> 16) / 255.0 | |
green = ((value & 0xFF00) >> 8) / 255.0 | |
blue = (value & 0xFF) / 255.0 | |
UIColor.colorWithRed(red, green: green, blue: blue, alpha: alpha) | |
end | |
else | |
UIColor.clearColor | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment