Skip to content

Instantly share code, notes, and snippets.

@martinbowling
Created September 13, 2012 23:25
Show Gist options
  • Save martinbowling/3718560 to your computer and use it in GitHub Desktop.
Save martinbowling/3718560 to your computer and use it in GitHub Desktop.
Helper Class for getting 16x9 Tall iPhone5+ images
using System;
using System.Drawing;
using MonoTouch.UIKit;
using System.IO;
public static class UIImageHelper
{
private static string tallMagic = "-568h@2x";
public static UIImage FromBundle16x9(string path)
{
//adopt the -568h@2x naming convention
if(Is16x9()){
string imagePath = Path.GetDirectoryName(path.ToString());
string imageFile = Path.GetFileNameWithoutExtension(path.ToString());
string imageExt = Path.GetExtension(path.ToString());
imageFile = imageFile + tallMagic + imageExt;
return UIImage.FromFile(Path.Combine(imagePath,imageFile));
}
else {
return UIImage.FromBundle(path.ToString());
}
}
public static bool Is16x9()
{
return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone && UIScreen.MainScreen.Bounds.Height * UIScreen.MainScreen.Scale >= 1136;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment