Define a color - ParkinT/RubyMotion_Life GitHub Wiki

How To

Define any color simply

def getColor(r, g, b)
  return UIColor.colorWithRed(r/255.0, green:g/255.0, blue:b/255.0, alpha:1.0)
end 

Another technique - a bit more Rubyesque is this

# 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