×

一些常用的iOS宏定义送给大家

消耗积分:1 | 格式:rar | 大小:0.3 MB | 2017-09-26

分享资料个

  1.获取屏幕宽度与高度

  #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

  #define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height

  2.获取通知中心

  #define LRNotificationCenter [NSNotificationCenter defaultCenter]

  3.设置随机颜色

  #define LRRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

  4.设置RGB颜色/设置RGBA颜色

  #define LRRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

  #define LRRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]

  // clear背景颜色

  #define LRClearColor [UIColor clearColor]

  5.自定义高效率的 NSLog

  项目开发中,我们会在许多地方加上Log,但是发布的时候又不想用这些Log,我们也不可能一个一个的删除,所以自定义Log是必然的!

  #ifdef DEBUG

  #define LRLog(。。.) NSLog(@“%s 第%d行 \n %@\n\n”,__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])

  #else

  #define LRLog(。。.)

  #endif

  6.弱引用/强引用

  #define LRWeakSelf(type) __weak typeof(type) weak##type = type;

  #define LRStrongSelf(type) __strong typeof(type) type = weak##type;

  一些常用的iOS宏定义送给大家

  

  7.设置 view 圆角和边框

  #define LRViewBorderRadius(View, Radius, Width, Color)\

  \

  [View.layer setCornerRadius:(Radius)];\

  [View.layer setMasksToBounds:YES];\

  [View.layer setBorderWidth:(Width)];\

  [View.layer setBorderColor:[Color CGColor]]

  8.由角度转换弧度 由弧度转换角度

  #define LRDegreesToRadian(x) (M_PI * (x) / 180.0)

  #define LRRadianToDegrees(radian) (radian*180.0)/(M_PI)

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !