解決方法的原作者:
http://artwalk.github.io/2017/10/23/Batch-replace-NamedColors-to-RGB-in-Storyboard/
簡(jiǎn)單說(shuō)明下
第一步尉桩,就是做個(gè)python文件贩幻,取名?NamedColors2RGB.py绢馍。
內(nèi)容如下
#!/usr/bin/env python
# -*- coding: utf-8 -*-
importos, json
printos.getcwd()
colorDict = {}
# read all colorset
forroot, dirs, filesinos.walk("./"):
fordindirs:
ifd.endswith(".colorset"):
colorK = d.split(".")[0]
print"found "+ colorK
forfileinfiles:
iffile =="Contents.json":
f = open(os.path.join(root, d, file))
jd = json.load(f)
rgb = jd["colors"][0]["color"]["components"]
colorDict[colorK] ='red="{}" green="{}" blue="{}" alpha="{}" colorSpace="calibratedRGB"'.format(rgb["red"], rgb["green"], rgb["blue"], rgb["alpha"])
print""
importre
# replacing
forroot, dirs, filesinos.walk("./"):
forfileinfiles:
iffile.endswith((".storyboard",".xib")):
path = os.path.join(root, file)
print"Replacing namedColor in "+ path
f = open(path)
nf = f.read()
f.close()
nf = re.sub(r" +\n",'', nf)
nf = re.sub(r" +
fork, vincolorDict.items():
nf = re.sub(r'name="{}"'.format(k), v, nf)
f = open(path,'w')
f.write(nf)
f.close()
Then,Xcode -> Project File -> Build Phases -> Add Build Phase -> Add Run Script
if["${CONFIGURATION}"="Release"];then
python NamedColors2RGB.py
fi
第二步胖齐,Xcode -> Project File -> Build Phases -> Add Build Phase -> Add Run Script
添加下面的代碼
if [ "${CONFIGURATION}" = "Release" ]; then
python NamedColors2RGB.py
fi
運(yùn)行一次,IB代碼就會(huì)有類(lèi)似下圖這種變化呀伙。之后正常發(fā)包就可以了补履。
需要注意的是,如果開(kāi)發(fā)時(shí)候想繼續(xù)使用NamedColorSet剿另,可不要把運(yùn)行py文件后的代碼上傳了箫锤。