Skip to content

Instantly share code, notes, and snippets.

@kmikael
Last active December 26, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmikael/7221495 to your computer and use it in GitHub Desktop.
Save kmikael/7221495 to your computer and use it in GitHub Desktop.
Generate a UIColor constructor from a given hex string

Given #f7dd37, this workflow will generate a line like this [UIColor colorWithRed:247.0 / 255.0 green:221.0 / 255.0 blue:55.0 / 255.0 alpha:1.0] and paste it into the frontmost application. http://cl.ly/SD9L

red, green, blue = '{query}'.match(/#?(..)(..)(..)/).to_a.drop(1).map(&:hex).map(&:to_f)
print "[UIColor colorWithRed:#{red} / 255.0 green:#{green} / 255.0 blue:#{blue} / 255.0 alpha:1.0]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment