Search code examples
iosiphonexcasset

How to use Image assets in iOS


I would like to use the launch images from the xcasset; I've already tried some ways but I can't get it works.

I've the standard LaunchImage asset, and the image file are called Default[@2x,...]. Using [UIImage imageNamed:@"LaunchImage"]; always return nil. I've also tried with @"Default", but no results.


Solution

  • If you Just want to use the compiled images separately in your application:

    By-default LaunchImage asset would generate following files:

    LaunchImage-700-Landscape@2x~ipad.png
    LaunchImage-700-Landscape~ipad.png
    LaunchImage-700-Portrait@2x~ipad.png
    LaunchImage-700-Portrait~ipad.png
    

    To find them use below:

    UIImage* image = [UIImage imageNamed:@"LaunchImage-700-Portrait"];
    

    Note: 3 steps required to setup the assets properly are mentioned below. Are you missing anything ?

    My Images:enter image description here

    Updating images in Launch Image source: enter image description here

    Drag and drop images in LaunchImage asset: enter image description here