Created
September 19, 2012 06:12
-
-
Save AdamSwinden/3747967 to your computer and use it in GitHub Desktop.
UIScreen Aspect Ratio (Detecting 4" display)
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
// | |
// 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 |
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
// | |
// 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