Created
September 13, 2012 23:25
-
-
Save martinbowling/3718560 to your computer and use it in GitHub Desktop.
Helper Class for getting 16x9 Tall iPhone5+ images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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