有的小姐姐小哥哥比较喜欢用xib,或者当我们的业务状态非常多的时候,可以利用xib+UIStackView来迅速开发,都知道大量的xib会非常的耗性能,但是偶尔一两个也是可以的。
我是一个偏向于代码布局的,灵活性高,易于维护,虽然有时候一些初始化代码及布局代码可能会达到三百多行,但是还是喜欢用代码来布局。
如果我们用组件化开发的话,再组件化中怎么将xib文件转为nib。奉上简便的脚本文件,来解放你的双手!!!
使用流程:
1.将xib文件或包含xib文件的文件夹 以及 nib.sh 放在同一个目录下;
2.cd 到该目录下
3.终端执行命令 bash nib.sh xib文件或文件夹
报错:
xcodebuild’ requires Xcode, but active developer directory ‘/Library/Developer/CommandLineTools’ 。。。
解决该问题只需要设置xcode中的命令行工具:打开Xcode -> 左上角Xcode -> Preference… -> Locations -> Command Line Tools 选择最新即可。
脚本文件地址
脚本代码:
#!/bin/bash
# 将xib编译成nib文件
function transitionToNib(){
ibtool --errors --warnings --output-format human-readable-text --compile ibtool --errors --warnings --output-format human-readable-text --compile $1 $2
}
#处理输入的参数 并编译成nib
function handlFile(){
ORIGIN=$1
echo $1
XIBFILE=${ORIGIN##*/}
echo "$XIBFILE xib文件"
FILENAME="${ORIGIN%.*}"
NIBFILEDIR=$FILENAME".nib"
NIBFILE=${NIBFILEDIR##*/}
echo "$FILENAME file名"
echo "$NIBFILE nib文件"
transitionToNib $NIBFILE $XIBFILE
}
#循环目录,将每个xib编译成nib
function scandir() {
local cur_dir parent_dir workdir
workdir=$1
cd ${workdir}
if [ ${workdir} = "/" ]
then
cur_dir=""
else
cur_dir=$(pwd)
fi
for dirlist in $(ls ${cur_dir})
do
if test -d ${dirlist};then
cd ${dirlist}
scandir ${cur_dir}/${dirlist}
cd ..
else
echo "${cur_dir}/${dirlist} 子文件"
handlFile ${cur_dir}/${dirlist}
fi
done
}
#判断是否有输入参数 需输入一个xib文件 或 一个只包含xib的文件 注意,xib文件名不能为空,否则不会被编译成nib
if [ ! -n "$1" ] ;then
echo "you have not input a xibfile or directory of xibfile!"
return
else
echo "the word you input is $1"
fi
#判断是文件还是文件夹
if test -d $1
then
echo "you input a directory"
scandir $1
exit 1
elif test -f $1
then
echo "you input a xibfile "
handlFile $1
exit 1
else
echo "the Directory isn't exist which you input,pls input a new one!!"
exit 1
fi