常用的宏

//判断ios版本宏
#define IOS8_OR_LATER( [[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending )
#define IOS7_OR_LATER( [[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending )
#define IOS6_OR_LATER( [[[UIDevice currentDevice] systemVersion] compare:@"6.0"] != NSOrderedAscending )
#define IOS5_OR_LATER( [[[UIDevice currentDevice] systemVersion] compare:@"5.0"] != NSOrderedAscending )
#define IOS4_OR_LATER( [[[UIDevice currentDevice] systemVersion] compare:@"4.0"] != NSOrderedAscending )
#define IOS3_OR_LATER( [[[UIDevice currentDevice] systemVersion] compare:@"3.0"] != NSOrderedAscending )
//判断屏幕
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_SCREEN_4_INCH([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_SCREEN_35_INCH([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
//考虑转屏的影响,按照实际屏幕方向(UIDeviceOrientation)的宽高
    #define SCREEN_WIDTH ([UIScreenmainScreen].bounds.size.width)
    #define SCREEN_HEIGHT ([UIScreenmainScreen].bounds.size.height)
    #define STATUSBAR_HEIGHT ([UIApplicationsharedApplication].statusBarFrame.size.height)
//不考虑转屏的影响,只取竖屏(UIDeviceOrientationPortrait)的宽高
    #define SCREEN_WIDTH MIN([UIScreenmainScreen].bounds.size.width, [UIScreenmainScreen].bounds.size.height)
    #define SCREEN_HEIGHT MAX([UIScreenmainScreen].bounds.size.height, [UIScreenmainScreen].bounds.size.width)
    #define STATUSBAR_HEIGHT MIN([UIApplicationsharedApplication].statusBarFrame.size.width, [UIApplicationsharedApplication].statusBarFrame.size.height)
//获取app版本号
#define APP_VERSION  [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
//字体相关
#define FONT(_SIZE) [UIFont systemFontOfSize:_SIZE]
#define BOLDFONT(_SIZE) [UIFont boldSystemFontOfSize:_SIZE]
#define IMAGESTRING(_STRING) [UIImage imageFromString:_STRING]
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kStrWidth(_STR,_FONT,_HEIGHT) [_STR sizeWithFont:_FONT byHeight:_HEIGHT].width
#define kStrHeight(_STR,_FONT,_WIDTH) [_STR sizeWithFont:_FONT byWidth:_WIDTH].height
#define kImageBorderColor HEX_RGB(0xe7e7e7).CGColor
//设备参数
#define SYSTEM_VERSION              [[[UIDevice currentDevice] systemVersion] floatValue]
#define IS_IOS7                     (SYSTEM_VERSION >= 7)
#define SCREEN_HEIGHT               [[UIScreen mainScreen] bounds].size.height
#define STATUSBAR_HEIGHT            [[UIApplication sharedApplication] statusBarFrame].size.height
#define FULL_WIDTH                  [[UIScreen mainScreen] bounds].size.width
#define FULL_HEIGHT                 (SCREEN_HEIGHT - ((SYSTEM_VERSION >= 7) ? 0 : STATUSBAR_HEIGHT))
#define SCREEN_WIDTH                FULL_WIDTH
//等比放大问题,适配iphone6 和 plus
#define SCALE_X (FULL_WIDTH/320.f)
#define GET_WIDTH(width) width*SCALE_X
#define GET_HEIGHT(height) height*SCALE_X
#define RANDOMCOLOR [UIColor colorWithRed:(arc4random() % 255)/255.0f green:(arc4random() % 255)/255.f blue:(arc4random() % 255)/255.f alpha:1]
在工程prefix里如下定义即可到处用。static const NSString *LLBTTTNotification = @"LLBTTTNotification";

你可能感兴趣的:(常用的宏)