iOS开发中的常用宏定义

在iOS开发的过程中合理的使用宏定义能够极大提高编码的速度,下面是一些常用的宏定义,部分内容来自互联网

Log

//  调试状态, 打开LOG功能
#ifdef DEBUG
#define GLLog(...) NSLog(__VA_ARGS__)
#define GLLogMethod NSLog(@"%s", __func__)
#else
//  发布状态, 关闭LOG功能
#define GLLog(...)
#define GLLogMethod
#endif

颜色

#define RGB(r,g,b) [UIColor colorWithRed:r/255. green:g/255. blue:b/255. alpha:1.]

#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255. green:g/255. blue:b/255. alpha:a/100.]

//16进制的颜色
#define RGBHex(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 MainColor RGB(107,185,103)
//主背景色
#define MainBgColor RGB(238,240,243)

屏幕的长度和宽度

#define UIHeight [[UIScreen mainScreen] bounds].size.height
#define UIWidth [[UIScreen mainScreen] bounds].size.width

字体font

#define kFont(x) [UIFont systemFontOfSize:x]
#define kBoldFont(x) [UIFont boldSystemFontOfSize:x]

#define MainFont14 [UIFont systemFontOfSize:14]
#define MainFont15 [UIFont systemFontOfSize:15]
#define MainFont12 [UIFont systemFontOfSize:12]

app名字及版本号

//app名字
#define AppName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
//app版本号
#define AppVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]

尺寸适配

#define Match(x) (x * UIWidth / 320)

其他

//通知中心
#define GLNotifyCenter [NSNotificationCenter defaultCenter]

//main bundle加载xib文件
#define MainBundle(xx) [[[NSBundle mainBundle] loadNibNamed:xx owner:self options:nil] lastObject]

//个人设置中心
#define GLUserCenter [NSUserDefaults standardUserDefaults]

//weakSelf
#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;
原文地址:https://www.cnblogs.com/iyou/p/4818022.html