博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一些宏
阅读量:4679 次
发布时间:2019-06-09

本文共 4215 字,大约阅读时间需要 14 分钟。

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)

 

 

转载于:https://www.cnblogs.com/leeAsia/p/3413716.html

你可能感兴趣的文章
CF715C Digit Tree
查看>>
二分法练习1
查看>>
QT 制作串口调试小助手----(小白篇)
查看>>
前端MVC实践之hellorocket——by张舒彤
查看>>
OptimalSolution(2)--二叉树问题(3)Path路径问题
查看>>
IPC 之 Messenger 的使用
查看>>
爱情八十六课,等得不是爱情
查看>>
企业网站建设流程
查看>>
数据库的显示、创建、使用 、用户授权管理及忘记root用户后重置密码
查看>>
ES5和ES6中的继承 图解
查看>>
macos 下usb键盘问题.
查看>>
SQL函数学习(十六):STUFF()函数
查看>>
CI CLI执行方式
查看>>
201521123092《Java程序设计》第七周学习总结
查看>>
day23---ajax跨域解决---JSONP
查看>>
redis封装 get查询/删除key/keys查询
查看>>
移动端自适应js
查看>>
Pro Android学习笔记(三二):Menu(3):Context菜单
查看>>
java中用StringBuffer写文件换行
查看>>
c#ASP.NET中页面传值共有这么几种方式
查看>>