Last active
May 22, 2018 04:44
-
-
Save jimrutherford/3788472 to your computer and use it in GitHub Desktop.
Device Detection Macros for iOS
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
/** String: Identifier **/ | |
#define DEVICE_IDENTIFIER ( ( IS_IPAD ) ? DEVICE_IPAD : ( IS_IPHONE ) ? DEVICE_IPHONE , DEVICE_SIMULATOR ) | |
/** String: iPhone **/ | |
#define DEVICE_IPHONE @"iPhone" | |
/** String: iPad **/ | |
#define DEVICE_IPAD @"iPad" | |
/** String: Device Model **/ | |
#define DEVICE_MODEL ( [[UIDevice currentDevice ] model ] ) | |
/** String: Localized Device Model **/ | |
#define DEVICE_MODEL_LOCALIZED ( [[UIDevice currentDevice ] localizedModel ] ) | |
/** String: Device Name **/ | |
#define DEVICE_NAME ( [[UIDevice currentDevice ] name ] ) | |
/** Double: Device Orientation **/ | |
#define DEVICE_ORIENTATION ( [[UIDevice currentDevice ] orientation ] ) | |
/** String: Simulator **/ | |
#define DEVICE_SIMULATOR @"Simulator" | |
/** BOOL: Detect if device is an iPad **/ | |
#define IS_IPAD ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) | |
/** BOOL: Detect if device is an iPhone or iPod **/ | |
#define IS_IPHONE ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) | |
/** BOOL: Detect if device is an iPhone 5 **/ | |
#define IS_IPHONE_5 ( IS_IPHONE ? CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136)) ? YES : NO : NO ) | |
/** BOOL: IS_RETINA **/ | |
#define IS_RETINA ( [[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2 ) | |
/** BOOL: Detect if device is the Simulator **/ | |
#define IS_SIMULATOR ( TARGET_IPHONE_SIMULATOR ) | |
#define ApplicationDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate]) | |
#define UserDefaults [NSUserDefaults standardUserDefaults] | |
#define NotificationCenter [NSNotificationCenter defaultCenter] | |
#define SharedApplication [UIApplication sharedApplication] | |
#define Bundle [NSBundle mainBundle] | |
#define MainScreen [UIScreen mainScreen] | |
#define ShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES | |
#define HideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO | |
#define NetworkActivityIndicatorVisible(x) [UIApplication sharedApplication].networkActivityIndicatorVisible = x | |
#define NavBar self.navigationController.navigationBar | |
#define TabBar self.tabBarController.tabBar | |
#define NavBarHeight self.navigationController.navigationBar.bounds.size.height | |
#define TabBarHeight self.tabBarController.tabBar.bounds.size.height | |
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width | |
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height | |
#define TouchHeightDefault 44 | |
#define TouchHeightSmall 32 | |
#define ViewWidth(v) v.frame.size.width | |
#define ViewHeight(v) v.frame.size.height | |
#define ViewX(v) v.frame.origin.x | |
#define ViewY(v) v.frame.origin.y | |
#define SelfViewWidth self.view.bounds.size.width | |
#define SelfViewHeight self.view.bounds.size.height | |
#define RectX(f) f.origin.x | |
#define RectY(f) f.origin.y | |
#define RectWidth(f) f.size.width | |
#define RectHeight(f) f.size.height | |
#define RectSetWidth(f, w) CGRectMake(RectX(f), RectY(f), w, RectHeight(f)) | |
#define RectSetHeight(f, h) CGRectMake(RectX(f), RectY(f), RectWidth(f), h) | |
#define RectSetX(f, x) CGRectMake(x, RectY(f), RectWidth(f), RectHeight(f)) | |
#define RectSetY(f, y) CGRectMake(RectX(f), y, RectWidth(f), RectHeight(f)) | |
#define RectSetSize(f, w, h) CGRectMake(RectX(f), RectY(f), w, h) | |
#define RectSetOrigin(f, x, y) CGRectMake(x, y, RectWidth(f), RectHeight(f)) | |
#define DATE_COMPONENTS NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit | |
#define TIME_COMPONENTS NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit | |
#define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] | |
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] | |
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0 green:((c>>8)&0xFF)/255.0 blue:(c&0xFF)/255.0 alpha:1.0]; | |
#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment