Created
June 13, 2014 03:07
-
-
Save y-ogi/603774bd12b3e9f00fa4 to your computer and use it in GitHub Desktop.
python script for converting html color code to UIColor
This file contains 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
#!/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