dealloc里面释放对象
#if DEBUG #define MCRelease(x) [x release] #else #define MCRelease(x) [x release], x = nil #endif
//use dlog to print while in debug model#ifdef DEBUG# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);#else# define DLog(...)#endif
在不同系统区分代码
#ifdef __IPHONE_5_0 float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 5.0) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil]; }#endif
系统信息
#define NavigationBar_HEIGHT 44 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)#define SAFE_RELEASE(x) [x release];x=nil#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion]) #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
设备
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #if TARGET_OS_IPHONE//iPhone Device#endif #if TARGET_IPHONE_SIMULATOR//iPhone Simulator#endif
RGB颜色
#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)]#define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]
ARC监测
//ARC#if __has_feature(objc_arc) //compiling with ARC#else // compiling without ARC#endif
度,弧度
#pragma mark - degrees/radian functions #define degreesToRadian(x) (M_PI * (x) / 180.0)#define radianToDegrees(radian) (radian*180.0)/(M_PI)
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]
定义CGRECT
#define CGRectMake(a,b,c,d) CGRectMake((a)/320.0*[[UIScreen mainScreen] applicationFrame].size.width,(b)/460.0*[[UIScreen mainScreen] applicationFrame].size.height,(c)/320.0*[[UIScreen mainScreen] applicationFrame].size.width,(d)/460.0*[[UIScreen mainScreen] applicationFrame].siz
weak,strong
#define WEAKSELF typeof(self) __weak weakSelf = self;#define STRONGSELF typeof(weakSelf) __strong strongSelf = weakSelf;
//6.0一下兼容6.0枚举类型,避免版本导致的警告#define UILineBreakMode NSLineBreakMode#define UILineBreakModeWordWrap NSLineBreakByWordWrapping#define UILineBreakModeCharacterWrap NSLineBreakByCharWrapping#define UILineBreakModeClip NSLineBreakByClipping#define UILineBreakModeHeadTruncation NSLineBreakByTruncatingHead#define UILineBreakModeTailTruncation NSLineBreakByTruncatingTail#define UILineBreakModeMiddleTruncation NSLineBreakByTruncatingMiddle#define UITextAlignment NSTextAlignment#define UITextAlignmentLeft NSTextAlignmentLeft#define UITextAlignmentCenter NSTextAlignmentCenter#define UITextAlignmentRight NSTextAlignmentRight
版本兼容
#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)