Skip to content

Instantly share code, notes, and snippets.

@y-ogi
Created June 13, 2014 03:07
Show Gist options
  • Save y-ogi/603774bd12b3e9f00fa4 to your computer and use it in GitHub Desktop.
Save y-ogi/603774bd12b3e9f00fa4 to your computer and use it in GitHub Desktop.
python script for converting html color code to UIColor
#!/usr/bin/env python
import re
import sys
import optparse
def main(color):
print "[UIColor colorWithRed:%.3f green:%.3f blue:%.3f alpha:1.f]" % tuple([round(int(x, 16) / 255., 3) for x in re.findall('[a-fA-F0-9]{2}', color[1:] if color[0] == '#' else color)])
if __name__ == '__main__':
usage = "Usage: %prog code"
parser = optparse.OptionParser(usage)
(options, args) = parser.parse_args()
if not args:
parser.error("required code")
parser.print_help()
exit(1)
main(args[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment