Skip to content

Instantly share code, notes, and snippets.

@raulriera
Created October 3, 2012 02:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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/background@2x.png
// images/background-568h@2x.png
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","-568h@2x.png");
imagePath = imagePath.replace(".jpg","-568h@2x.jpg");
imagePath = imagePath.replace(".jpeg","-568h@2x.jpeg");
}
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