美文网首页
iOS开发 宏定义

iOS开发 宏定义

作者: LearningCoding | 来源:发表于2017-03-27 19:00 被阅读17次

在iOS开发中,合理的使用宏定义可以使我们少些好多代码

// MainScreen
#define Main_Screen      [[UIScreen mainScreen] bounds]
// MainScreen Height&Width
#define Main_Screen_Height     Main_Screen.size.height
#define Main_Screen_Width      Main_Screen.size.width

// 系统控件默认高度
#define StatusBarHeight        (20.f)
#define TopBarHeight           (44.f)
#define BottomBarHeight        (49.f)

// 颜色(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 colorWith0xColor(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]

// min到max的随机数
#define Random(min, max)    arc4random() % (max - min + 1) + min

// 在DEBUG模式下打印
#ifdef DEBUG
    #define wlog(...)   NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#elif RELEACE
    #define wlog(...)   
#else
    #define wlog(...)
#endif

// 预处理判断使用
#define DLEVEL 10
#if DLEVEL == 0
    #define STACK 0
#elif DLEVEL == 1
    #define STACK 1
#else
    #define STACK DLEVEL
#endif

// 预编辑 判断版本号
#ifdef _IPHONE_11_0
#endif

// 弱引用、强引用
#define WeakSelf(type)  __weak typeof(type) weak##type = type;
#define StrongSelf(type)  __strong typeof(type) type = weak##type;

// 给view设置圆角和边框
#define ViewBorderRadius(View, Radius, Width, Color) \
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]];

C预定义宏
DATE //进行预处理的日期(“Mmm dd yyyy”形式的字符串文字)
FILE // 代表当前源代码文件名的字符串文字
LINE // 代表当前源代码中的行号的整数常量
TIME // 源文件编译时间,格式微“hh:mm:ss”
func // 当前所在函数名

相关文章

  • IOS NSLog宏定义

    IOS NSLog宏定义 标签(空格分隔): IOS IOS NSLog宏定义 宏定义NSLog方法,不用加";"...

  • iOS开发实用技巧之变量的定义:const、static、ext

    参考文章:iOS 不要用宏来定义你的常量iOS开发实用技巧—const、static、extern简介iOS开发笔...

  • iOS 常用宏定义

    iOS 开发中使用一些常用宏定义可以大大提高开发效率,提高代码的重用性.以下是一些常用的宏定义: 像这些宏定义,在...

  • iOS开发常用的工具类和宏定义

    iOS开发常用的工具类和宏定义 开发总结的工具类和宏 https://github.com/xiaoChen66...

  • ios开发 -宏定义

    宏定义在很多方面都会使用,例如定义高度、判断iOS系统、工具类,还有诸如文件路径、服务端api接口文档。 ...

  • iOS开发 宏定义

    在iOS开发中,合理的使用宏定义可以使我们少些好多代码 C预定义宏DATE //进行预处理的日期(“Mmm dd...

  • iOS之宏定义

    iOS开发小技巧之--WeakSelf宏的进化 宏定义不是C语句,也无须使用分号结束 宏定义并不是变量,它甚至不是...

  • iOS常用宏定义

    该文章记录iOS开发中常见的宏定义 识别系统版本

  • iOS 开发小经验

    iOS 开发中你是否遇到这些经验问题(一)iOS 开发中你是否遇到这些经验问题(二)iOS 日常工作之常用宏定义大全

  • iOS开发中常用的宏定义

    iOS开发中常用的宏定义 尺寸宏 打印宏 替换NSLog来使用,debug模式下可以打印很多方法名,行信息。 #...

网友评论

      本文标题:iOS开发 宏定义

      本文链接:https://www.haomeiwen.com/subject/pssrottx.html