Photoshop hex RGB to a UIColor
February 2, 2012, 1:16 am
Adam (the awesome goCatch designer) and I got sick of converting from hex RGB colors to decimal UIColor initialisation params, so I wrote this script.
import sys
if (len(sys.argv) != 2):
print ("convert.py <hex color>")
sys.exit ()
color = sys.argv[1]
if (len (color) != 8):
print ("convert.py <8 char hex color>")
sys.exit ()
# get the two character chunks
red = color[:2]
green = color[2:4]
blue = color[4:6]
alpha = color[6:8]
decRed = int (red,16) / 255.0
decGreen = int (green,16) / 255.0
decBlue = int (blue,16) / 255.0
decAlpha = int (alpha,16) / 255.0
#iOS code
print ("[UIColor colorWithRed:%.4f green:%.4f blue:%.4f alpha:%.4f];" % (decRed, decGreen, decBlue, decAlpha))
#Android code
print ("private static final int COLOR = 0x"+alpha+red+green+blue);
Yep it also does an Android static final int. We love Android too ;)
Permalink - Tags: Development,Android,iPhone