Hi All ! In this post, you’ll find a script. This shell script is going to help you to generate XCAssets.
Why do we need XCAssets?
In earlier XCode5, we’re forced to (or it is more preferable to) manage assets/images of the project using XCAssets. For example have a quick look into following snap-shot
So, XCAssets provide us more simpler way to manage assets of project. But what are the challanges
- We have to create first image-sets.
- Move image-sets into appropriate folder as per convenience
- Set name for the image-set
- Set name for 1x image as per given to the name of image-set (more preferable for supporting older iOS)
- Set name for 2x image as per given to the name of image-set (more preferable for supporting older iOS)
- Make sure 1x image is exactly half than the 2x image.
- So, as a developer, we have to ask designer to provide images in both dimensions. If designer is lazy in giving appropriate name, we as a developer have to set the name of ‘image-set’, ‘image1x’ & ‘image2x’. which literally indicates a laborious job as a project may have number of images.
So, I tried to eliminate this laborious job with a shell-script.
What you have need to do before executing following script?
- Please read post very carefully & don’t start executing script.
- Get the sliced images from the designer.
- Make sure you’ve all images for retina resolution.
- If files are not as per the naming convention – having suffix of @2x.png, please apply @2x.png to all files <= this is very important for correct output of shell-script.
- Make appropriate folders & move images into folders as per convenience. ALERT – Please do not add space to files or folders or any special characters. I’m not shell-script expert & couldn’t manage such in file-folders
- Here is an example directory structure, how it should look like. Make sure you’ve similar pattern in your directory structure.
- Open terminal & make sure your working directory is root directory of your-design folder. Here in this case ‘Login’ is the root folder.
- Save following script & execute it by suffixing ‘sudo’ – here is the example screen-shot.
Here is the example screen-shot of output.
Now copy directory under your projects.xcassets directory & You’ll find all assets managed properly as follows.