美文网首页
iOS 开发常用宏定义

iOS 开发常用宏定义

作者: L小杰 | 来源:发表于2017-05-06 11:58 被阅读73次
///屏幕的宽度
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
///屏幕的高度
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
///storyboard
#define STO [UIStoryboard storyboardWithName:"Main" bundle:nil]
//定义字体函数
#define FONT(a)  [UIFont systemFontOfSize:a ]
//系统标准保存键值
#define UserDefaultStandard  [NSUserDefaults standardUserDefaults]
/** 弱引用*/
#define kWeakSelf(type)   __weak typeof(type) weak##type = type;
/** 强引用*/
#define kStrongSelf(type) __strong typeof(type) type = weak##type;
/** 由角度转换弧度*/
#define kDegreesToRadian(x)      (M_PI * (x) / 180.0)
/** 由弧度转换角度*/
#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI)
/** 获取沙盒 Document 路径*/
#define kDocumentPath       [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
/** 获取沙盒 temp 路径(注:iPhone 重启会清空)*/
#define kTempPath           NSTemporaryDirectory()
/** 获取沙盒 Cache 路径*/
#define kCachePath          [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
///重写log
#ifdef DEBUG
#define DLog(...) NSLog(__VA_ARGS__)
#else
#define DLog(...)
#endif
//定义颜色函数
#define RGBA(r,g,b,a)   [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
#define RGBCOLOR(a,b,c) RGBA(a,b,c,1.0)
#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]
// 控件尺寸适配的宏函数
#define kFit(x) (kScreenWidth*((x)/375))
//G-C-D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)
 
// 不堵塞线程并在主线程的延迟执行 timer:延迟时间,单位:秒;与主线程同步
#define GCDMainDelay(timer,block) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, INT64_C(timer) * NSEC_PER_SEC), dispatch_get_main_queue(), block)
// 将code调到主线程执行,与主线程同步
#define GCDMain(block) dispatch_async(dispatch_get_main_queue(), block) 

相关文章

  • iOS 常用宏定义

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

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

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

  • iOS开发中常用的宏

    以下为iOS开发中常用宏: 引用:ios开发常用的宏,大家一起来收集 参考:ios开发常用的宏,大家一起来收集~

  • iOS 开发小经验

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

  • iOS开发中常用的宏定义

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

  • iOS 开发常用宏定义

  • iOS开发常用宏定义

    做开发不久,经常会上网找一些资料,简书上的内容是看着比较顺眼的了;特此也想把平时工作中遇到的问题总结记录下来,希望...

  • iOS开发常用宏定义

    iOS 日常工作之常用宏定义大全iOS-OC中常见的一些宏YYCategories 目录 1、长、宽、高2、判断设...

  • iOS 开发常用宏定义

  • iOS开发常用宏定义

    判断设备类型iPad/iPhone#define IS_IPAD(UI_USER_INTERFACE_IDIOM(...

网友评论

      本文标题:iOS 开发常用宏定义

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