Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1472] Alloy - not able to retrieve assets from iPhone folder

GitHub Issuen/a
Resolution Date2014-10-01T15:10:00.000+0000
Affected Version/sn/a
Fix Version/sn/a
Labelsalloy, assets
ReporterSamie Syed
AssigneeShuo Liang


I am trying to access my assets from the app>assets>iphone>images directory. This is how I am trying to get the asset in code $.imageW.image = "/iphone/images/WalkthroughIllustration_01.png"; Doesn't work I have create the image view in the related XML file The only way I can get the image to display is if I move the asset outside of the iPhone directory, like this: $.imageW.image = "/images/WalkthroughIllustration_01.png"; BUT, I have read that by doing it that way, I will be unable to display retina images.


  1. Shuo Liang 2014-09-29

    Hi, Underneath the Resources/asset folder are iPhone and android folders - any resources placed in one of these folders will supersede the contents of the top-level Resources directory for a given platform. So you should not add one more folder "images" in it. Based on your case, All you have to do is placing your image resource in "iPhone" folder. Then when you reference a file(placed in iPhone folder) from your application, you should not include the platform in the name, as it is considered top-level resources. For example: 1. Place your image file WalkthroughIllustration_01.png under iPhone folder. 2. Then you can access it like:
    $.imageW.image = "WalkthroughIllustration_01.png";
    Hope this will help you. Regards, Shuo
  2. Samie Syed 2014-09-29

    Thanks Shuo, That worked after dumping the images in the Assets->Iphone path. However: 1) How can I test to see if the retina version of the image is loaded up instead? When I run the app in the iphone simulator (retina) and non retina, I am not sure what I am looking at. 2) What is the difference in file name between retina and non retina images i.e. "WalkthroughIllustration_01.png" is non retina but what is retina? 3) Retina images are normally larger in size, do I need to hardcode the width and height of say the view/imageview which has it as a background? If so what should I use? pixels, percent etc? Thanks
  3. Shuo Liang 2014-09-29

    On the iPhone, you have two display densities to deal with: the original iPhone/iPod density and the double-density "retina" displays. The retina displays, featured on the iPhone 4 and presumably newer models has twice the DPI of the earlier displays. Following Apple's scheme, retina images are named to match their non-retina counterparts, with "@2x" appended to the name. In your code, though, you don't worry about that suffix.
       var img = Ti.UI.createImageView({
           image: 'logo.png'
           /* logo@2x.png will be used automatically if it exists on iPhone 4 & iPad devices */
  4. Samie Syed 2014-09-29

    Thank you Shuo. So if I did this: var img = Ti.UI.createView({ BackgroundImage: 'logo.png', /* logo@2x.png will be used automatically if it exists on iPhone 4 & iPad devices */ top: 100 }); And say the non retina image is in the correct position by default at the right dimensions.top=100, will the retina image if it gets called stay in the same dimension? (or appear bigger) Given retina images are 2 times the size. If not, will I need to set the width and the height in code? If so what units should I use %, pixels etc
  5. Shuo Liang 2014-09-29

    It should in the same dimension.
  6. Samie Syed 2014-09-29

    Right, so I need to hardcode the width and height? If so, what units?
  7. Shuo Liang 2014-09-29

    Ye, you'd better hardcode the width and height of the imageView to keep you interface looking good. Here is the doc about the units: [http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.View-property-height]
  8. Samie Syed 2014-09-29

    Thanks, what units should I use? I am confused about the difference between dp and pixels. Not sure when to use either.
  9. Shuo Liang 2014-09-30

    dip : Density-independent pixels. A measurement which is translated natively to a corresponding pixel measure using a scale factor based on a platform-specific "default" density, and the device's physical density. System unit : A platform-dependent unit which is the default for how the system presents its view information to the native layout system. On Android this is pixels; on iOS it is dip. In theory, You can use both of them. But in default, Android use pixels, and IOS use dp.
  10. Samie Syed 2014-09-30

    Thanks again Shuo. If I do not specify the unit like this: height: 300dp, width: 300dp but do this instead height: 300, width: 300 Will titanium for the iphone, automatically set 'dp' as the default unit?
  11. Shuo Liang 2014-09-30

    ye, exactly.

JSON Source