Created
October 28, 2013 04:51
-
-
Save nothinking/7191594 to your computer and use it in GitHub Desktop.
iOS Macro
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
// define UIColor macro | |
#define UIColorRGBMake(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] | |
// iOS version check macro | |
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) | |
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) | |
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) | |
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) | |
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) | |
// iOS screen check macro | |
#define IS_SCREEN_3_5 ([[UIScreen mainScreen] bounds].size.height < 568.0)?YES:NO | |
// Getting right UIImage and CGImage pixel size according to device display (retina or not) | |
// http://www.daveoncode.com/2011/10/22/right-uiimage-and-cgimage-pixel-size-retina-display/ | |
// return true if the device has a retina display, false otherwise | |
#define IS_RETINA_DISPLAY() [[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f | |
// return the scale value based on device's display (2 retina, 1 other) | |
#define DISPLAY_SCALE IS_RETINA_DISPLAY() ? 2.0f : 1.0f | |
// if the device has a retina display return the real scaled pixel size, otherwise the same size will be returned | |
#define PIXEL_SIZE(size) IS_RETINA_DISPLAY() ? CGSizeMake(size.width/2.0f, size.height/2.0f) : size | |
// NSLog level | |
#ifdef DEBUG | |
#define DWITRACE( s, ... ) NSLog( @"TRACE - <%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#define DWIDEBUG( s, ... ) NSLog( @"DEBUG - <%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#define DWIINFO( s, ... ) NSLog( @"INFO - <%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#define DWIWARN( s, ... ) NSLog( @"WARN - <%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#define DWIERROR( s, ... ) NSLog( @"ERROR - <%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#elif INHOUSE | |
#define DWITRACE( s, ... ) | |
#define DWIDEBUG( s, ... ) | |
#define DWIINFO( s, ... ) | |
#define DWIWARN( s, ... ) NSLog( @"WARN - <%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#define DWIERROR( s, ... ) NSLog( @"ERROR - <%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#else | |
#define DWITRACE( s, ... ) | |
#define DWIDEBUG( s, ... ) | |
#define DWIINFO( s, ... ) | |
#define DWIWARN( s, ... ) | |
#define DWIERROR( s, ... ) | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment