Skip to content

Instantly share code, notes, and snippets.

@AdamSwinden
Created September 19, 2012 06:12
Show Gist options
  • Save AdamSwinden/3747967 to your computer and use it in GitHub Desktop.
Save AdamSwinden/3747967 to your computer and use it in GitHub Desktop.
UIScreen Aspect Ratio (Detecting 4" display)
//
// UIScreen+AspectRatio.h
//
// Created by Adam Swinden on 14/09/2012.
// Copyright (c) 2012 The OTHER Media. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef enum {
UIScreenAspectRatioUnknown,
UIScreenAspectRatio4by3,
UIScreenAspectRatio16by9
} UIScreenAspectRatio;
@interface UIScreen (AspectRation)
@property (nonatomic, readonly) UIScreenAspectRatio aspectRatio;
@end
//
// UIScreen+AspectRatio.m
//
// Created by Adam Swinden on 14/09/2012.
// Copyright (c) 2012 The OTHER Media. All rights reserved.
//
#import "UIScreen+AspectRatio.h"
@implementation UIScreen (AspectRation)
- (UIScreenAspectRatio)aspectRatio {
float ratio = self.bounds.size.width / self.bounds.size.height;
if (ratio == 320.0f/480.0f || ratio == 480.0f/320.0f || ratio == 1024.0f/768.0f || ratio == 768.0f/1024.0f) return UIScreenAspectRatio4by3;
else if (ratio == 320.0f/568.0f || ratio == 568.0f/320.0f) return UIScreenAspectRatio16by9;
return UIScreenAspectRatioUnknown;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment