个人使用的 iOS 开发宏定义

2015-10-23 ios

都是项目中常用的,16进制色值转换,默认字体设置字号大小,获取当前Version,Build,沙盒路径,缓存路径,屏幕物理宽、高,基于iPhone5尺寸的缩放值,当前手机版本,weakself等等。

需要的就直接拷走好啦。

/*--------------------------------开发中常用到的宏定义-----------------------------------*/

// 颜色的转换
#define RGBCOLOR(r,g,b)             [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#define RGBACOLOR(r,g,b,a)          [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

//16进制色值
#define HexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define HexRGBAlpha(rgbValue, a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]

//设置系统默认字体的字号
#define FONT(x)             [UIFont systemFontOfSize:x]

//当前build号
#define Current_Build                [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
#define Current_Version                [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//常用系统库
#define USER_DEFAULT                [NSUserDefaults standardUserDefaults]
#define NOTIFICATION_CENTER         [NSNotificationCenter defaultCenter]

//沙盒存储路径
#define HomeDirectory               [NSHomeDirectory() stringByAppendingString:@"/Documents/"]

//缓存路径
#define APP_CACHES_PATH             [NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]

//屏幕物理宽、高
#define APP_SCREEN_WIDTH            [UIScreen mainScreen].bounds.size.width
#define APP_SCREEN_HEIGHT           [UIScreen mainScreen].bounds.size.height

//与iPhone5比较的尺寸缩放值
#define kScaleFrom_iPhone5_Desgin(_X_) (_X_ * (APP_SCREEN_WIDTH/320))

//手机版本
#define Current_device_vesion       [[[UIDevice currentDevice] systemVersion] floatValue]

//按屏幕尺寸确定手机
#define iPhone5                     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

//比较当前系统版本号与输入值(NSString)
#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)

//weakself 用与防止循环引用
#define WS(weakSelf)                __weak __typeof(&*self)weakSelf = self;

以后遇到新的好用的宏定义也会添加到这里,谢谢您的阅读。

Comments
Write a Comment