Skip to content

Instantly share code, notes, and snippets.

@raulriera
Created October 3, 2012 02:04
Show Gist options
  • Save raulriera/3824516 to your computer and use it in GitHub Desktop.
Save raulriera/3824516 to your computer and use it in GitHub Desktop.
Load iPhone5 retina graphics
// Assuming you have the images following images, this should work fine
// images/[email protected]
// images/[email protected]
require("ImageHelper");
var window = Titanium.UI.createWindow({
title: "My awesome window",
backgroundImage: parse568hImages("/images/background.png")
});
// I am pretty sure there is a sexier approach, but this works nicely
var isPhone5 = Ti.Platform.displayCaps.platformHeight == 568;
parse568hImages = function(imagePath) {
if (isPhone5){
// Do this because the filename could contain dots
imagePath = imagePath.replace(".png","[email protected]");
imagePath = imagePath.replace(".jpg","[email protected]");
imagePath = imagePath.replace(".jpeg","[email protected]");
}
return imagePath;
};
@sandrolain
Copy link

You could use:

imagePath = imagePath.replace(/\.(png|jpg|jpeg)$/i, "-568h@2x.$1");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment