解决方法的原作者:
http://artwalk.github.io/2017/10/23/Batch-replace-NamedColors-to-RGB-in-Storyboard/
简单说明下
第一步,就是做个python文件,取名 NamedColors2RGB.py。
内容如下
#!/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
运行一次,IB代码就会有类似下图这种变化。之后正常发包就可以了。
需要注意的是,如果开发时候想继续使用NamedColorSet,可不要把运行py文件后的代码上传了。
网友评论