iOS组件化中xib转nib

有的小姐姐小哥哥比较喜欢用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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值