In everyday development, the definition of macros can improve efficiency and bug resolution speed. I have listed the macros that I often use in development, and added macros collected by other colleagues. Personally think ‘hong’ is god gives us a pig knife!! ____ hope to help you…. ___ Switch macro #define APP_SWITCH_END (__OFF__) Parameter macro #define APP_HEIGHT_NUMBER (0.2F) Font macro #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)] Macro #define DEVICE_TITLE_COLOR (@”# ff5D5D “) // RGB color conversion (hexadecimal ->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] A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] #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) // Background color #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0] // Clear the background color #define CLEARCOLOR [UIColor CLEARCOLOR] #pragma markcolor 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)] size macro // to use instead of NSLog, debug mode can print many method names, line information. #ifdef DEBUG #defineDLog(fmt, …) NSLog((@”%s [Line %d] ” fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else #define DLog(…) #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] 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)