Adding Image Assets - nhan/ios_guides GitHub Wiki

Asset Catalogs are a new feature in XCode 5, and it makes asset management easy. To add assets to a project, follow the steps below.

Step 1: Select the asset catalog

As in the screenshot above, click Images.xcassets in the project navigator to bring up the Asset Catalog for the project.

Step 2: Add Image Set

To add an image to the project, create a new image set. Drag the png asset (jpeg won't work) from the Finder to the 1X or 2X slot. In a production app, you should include both the standard (1X) as well as retina (2X) asset. During development, you can add only one asset and XCode will automatically create the other one, although it may look blurry.

Step 3: Using the image set

Example 1: Using the image set in Interface Builder

Any control that has images like UIImageViews or UIButtons can set images in Interface Builder. Any image set in the Asset Catalog will be listed in the image drop down menus.

Example 1: Using the image set programatically

To access images in the Asset Catalog programatically, create UIImages using the imageNamed: method as shown in the snippet below.

Objective-C

UIImage *chat = [UIImage imageNamed:@"Chat"];
UIImageView *chatImageView = [[UIImageView alloc] initWithImage:chat];

Swift

var chat = UIImage(named: "Chat")
var chatImageView = UIImageView(image: chat)

App Icon and Launch Image

To set the app icon, simply select "App Icon" in the asset catalog and drag a .png file into the appropriate bucket. The App Icon expects various sizes for production, although you can use just one during development. Similarly, in production, the Launch Image expects 3.5" and 4" images, but you can use just one during development.

For the launch image, you will need to configure the Launch Image Target, change the Launch Image Source to create a new asset catalog, drag the images to the catalog, and delete the entry defined in Launch Screen file.

Note that in XCode 6, storyboard files are used instead of launch images defined by the Launch Screen file. If this file is left blank, then the Launch Image source gets used to render. You must also delete the LaunchScreen.xib file from the project for the launch images to be used, which the GIF above doesn't show.