Skip to content

Instantly share code, notes, and snippets.

@narfdotpl
Created November 18, 2014 12:30
Show Gist options
  • Save narfdotpl/47120a6fca5b001fee30 to your computer and use it in GitHub Desktop.
Save narfdotpl/47120a6fca5b001fee30 to your computer and use it in GitHub Desktop.
def f(s):
return '%.3f' % (int(s, 16) / 255.0)
def rgb(s):
print '[UIColor colorWithRed:%s green:%s blue:%s alpha:1],' % \
tuple(f(s.lstrip('#')[i : i + 2]) for i in range(0, 6, 2))
rgb('ffffff') # [UIColor colorWithRed:1.000 green:1.000 blue:1.000 alpha:1],
rgb('ff0000') # [UIColor colorWithRed:1.000 green:0.000 blue:0.000 alpha:1],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment