Created
June 13, 2013 13:28
-
-
Save davidortinau/5773668 to your computer and use it in GitHub Desktop.
Xamarin.iOS util to measure/detect iPhone 5 screen and pull the right image from the bundle.
This file contains 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.IO; | |
using MonoTouch.UIKit; | |
namespace | |
{ | |
public static class ScreenResolutionUtil | |
{ | |
public static bool IsTall | |
{ | |
get { | |
return UIDevice.CurrentDevice.UserInterfaceIdiom | |
== UIUserInterfaceIdiom.Phone | |
&& UIScreen.MainScreen.Bounds.Size.Height | |
* UIScreen.MainScreen.Scale >= 1136; | |
} | |
} | |
public static int ScreenHeight | |
{ | |
get { | |
return (IsTall) ? 568 : 480; | |
} | |
} | |
private static string tallMagic = "-568h@2x"; | |
public static UIImage FromBundle16x9(string path) | |
{ | |
//adopt the -568h@2x naming convention | |
if(IsTall) | |
{ | |
var imagePath = Path.GetDirectoryName(path.ToString()); | |
var imageFile = Path.GetFileNameWithoutExtension(path.ToString()); | |
var imageExt = Path.GetExtension(path.ToString()); | |
imageFile = imageFile + tallMagic + imageExt; | |
return UIImage.FromBundle(Path.Combine(imagePath,imageFile)); | |
} | |
else | |
{ | |
return UIImage.FromBundle(path.ToString()); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment