使用链接将~ipad资源指向@ 2x资源

时间:2012-04-19 06:52:23

标签: iphone ios

我一直在寻找解决复制数百个@2x文件的问题的解决方案,只是为了重命名~ipad。我尝试了一些主要涉及在代码中进行操作的想法。我将发布我自己的问题的答案我发现效果很好:使用符号链接将~ipad指向@2x个文件。

我只是想在此处记录,因为我在搜索中没有看到这个解决方案。

1 个答案:

答案 0 :(得分:4)

诀窍是创建指向@2x文件的链接并命名链接~ipad

这不是Finder中的“别名”命令。

手动您使用终端并输入以下内容:

ln -s image@2x.png image~ipad.png

现在,当您运行代码时,任何智能抓取设备相应文件的UIImage方法在iPad上运行时都会使用@2x文件。链接大约是磁盘上的16个字节,因此可以节省大量存储空间。

我还写了一个小的bash脚本来自动浏览目录并为它找到的每个~ipad文件创建@2x个链接:

#! /bin/sh

# Script to batch create symlinks that point ~ipad files to @2X files

# To run:
# Copy to the directory where the files are located
# Enter the following at the terminal prompt:
# bash create_ipad_image_links.txt

# For every @2x file we find in this directory we create a symlink

for file in *@2x.png
do
  echo "link: ${file//@2x/~ipad} to: $file" 
  ln -s $file ${file//@2x/~ipad}
done

上面代码中的使用说明。如果可以以任何方式改进,请评论。我确定有更好的(更光滑的?)方法来解决这个问题。