在日常的开发中,宏的定义可以提高效率,和解决bug的速度。
本人讲开发中常用到的宏列了出来,并加入了其他同仁收集的宏。
个人觉得‘宏’就是上帝赐给我们的一把杀猪刀!!!
____希望能够帮助你....___
开关宏
#define APP_SWITCH_END (__OFF__)
参数宏
#define APP_HEIGHT_NUMBER (0.2f)
字体宏
#define APP_FONT_DISPLAY_LIGHT @"SFUIDisplay-Light"
#define APP_FONT_DISPLAY_REGULAR @"SFUIDisplay-Regular"
#define APP_FONT_DISPLAY_BOLD @"SFUIDisplay-Bold"
#define APP_FONT_TEXT_LIGHT @"SFUIText-Light"
#define APP_FONT_TEXT_REGULAR @"SFUIText-Regular"
#define APP_FONT_TEXT_BOLD @"SFUIText-Bold"
#define APP_USE_DISPLAY_LIGHT(fontSize) [UIFont fontWithName:APP_FONT_DISPLAY_LIGHT size:(fontSize)]
#define APP_USE_DISPLAY_BOLD(fontSize) [UIFont fontWithName:APP_FONT_DISPLAY_BOLD size:(fontSize)]
//后面两个字节传入字体的大小就可以使用,字体是用的上方定义的宏
颜色宏
#define DEVICE_TITLE_COLOR (@"#ff5d5d")
// rgb颜色转换(16进制->10进制)
#define UIColorFromRGB(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]
//带有RGBA的颜色设置
#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
// 获取RGB颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)
//背景色
#define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]
//清除背景色
#define CLEARCOLOR [UIColor clearColor]
#pragma mark - color functions
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
尺寸宏
//替换NSLog来使用,debug模式下可以打印很多方法名,行信息。
#ifdef DEBUG
#defineDLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif
//直接替换NSLog
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif
系统宏
//获取版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]
//获取当前语言
#defineCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
//判断是真机还是模拟器
#ifTARGET_OS_IPHONE
//iPhone Device
#endif
#ifTARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
尺寸宏
#define StatusBar_HEIGHT 20
#define NavigationBar_HEIGHT 44
#define NavigationBarIcon 20
#define TabBar_HEIGHT 49
#define TabBarIcon 30
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)