Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created June 13, 2013 13:28
Show Gist options
  • Save davidortinau/5773668 to your computer and use it in GitHub Desktop.
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.
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