在日常的開發(fā)中,宏的定義可以提高效率,和解決bug的速度。
本人講開發(fā)中常用到的宏列了出來啄寡,并加入了其他同仁收集的宏。
個人覺得‘宏’就是上帝賜給我們的一把殺豬刀!!!
____希望能夠幫助你....___
開關宏
#define APP_SWITCH_END? ? ? ? ? ? ? ? ? (__OFF__)
參數(shù)宏
#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)]
//后面兩個字節(jié)傳入字體的大小就可以使用汹族,字體是用的上方定義的宏
顏色宏
#define DEVICE_TITLE_COLOR? ? ? ? ? ? ? ? ? ? ? (@"#ff5d5d")
// rgb顏色轉(zhuǎn)換(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
系統(tǒng)宏
//獲取版本
#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)