Created
November 3, 2012 02:58
-
-
Save tadamatu/4005648 to your computer and use it in GitHub Desktop.
Screen State Library
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
/* ======================================== | |
ScreenStateLibrary.h | |
======================================== */ | |
#import <Foundation/Foundation.h> | |
@interface ScreenStateLibrary : NSObject | |
//4インチスクリーン判定 | |
//YES=4inch、NO=4inch以外(3.5inch or iPad) | |
+(BOOL)is4inch; | |
//iPad判定 | |
//YES=iPad、NO=iPad以外 | |
+(BOOL)isPad; | |
//Retinaディスプレイ判定 | |
//YES=Retinaディスプレイ、NO=Retinaディスプレイ以外 | |
+(BOOL)isRetina; | |
@end | |
/* ======================================== | |
ScreenStateLibrary.m | |
======================================== */ | |
#import "ScreenStateLibrary.h" | |
@implementation ScreenStateLibrary | |
//4インチスクリーン判定 | |
+(BOOL)is4inch { | |
//iPadの場合はNOを返却 | |
if ([self isPad]) { return NO; } | |
//画面サイズ判定(4インチの場合、320x568となる) | |
return ([[UIScreen mainScreen] bounds].size.height >= 568.0); | |
} | |
//iPad判定 | |
+(BOOL)isPad{ | |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); | |
} | |
//Retinaディスプレイ判定 | |
+(BOOL)isRetina{ | |
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] | |
&& [[UIScreen mainScreen] scale] == 2.0) { | |
return YES; | |
} else { | |
return NO; | |
} | |
} | |
@end | |
/* ======================================== | |
使い方 | |
======================================== */ | |
-(void)viewLayout4inch { | |
//4インチスクリーンのレイアウト | |
} | |
-(void)viewLayoutDefault { | |
//4インチ以外のスクリーンのレイアウト | |
} | |
- (void)loadView { | |
//スクリーンサイズによる画面調整 | |
if ([ScreenStateLibrary is4inch]) { | |
[self viewLayout4inch]; | |
} else { | |
[self viewLayoutDefault]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment