IOS 常用的宏定义(#define)
2024-09-06 15:32:13
开发中经常用到的常量定义(随时更行):
与UIView相关
//获取View的frame属性
#define GetViewWidth(view) view.frame.size.width
#define GetViewHeight(view) view.frame.size.height
#define GetViewX(view) view.frame.origin.x
#define GetViewY(view) view.frame.origin.y
与屏幕相关
//屏幕尺寸(宽高)常量
#define GetScreenWidth [[UIScreen mainScreen] bounds].size.width
#define GetScreenHeight [[UIScreen mainScreen] bounds].size.height
与系统版本相关
//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define IOS6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
#define IOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)
#define IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 9.0)
#define IOS9 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 10.0)
与UIColor相关
//取得对应的UIcolor
#define UIColorFromRGB(R, G, B) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:1.0f]
#define UIColorFromRGBA(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]
#define UIColorFromHex(Hex) [UIColor colorWithRed:((Hex & 0xFF0000) >> 16)/255.0f green:((Hex & 0xFF00) >> 8)/255.0f blue:((Hex & 0xFF))/255.0f alpha:1.0f]
#define UIColorFromHexA(Hex, A) [UIColor colorWithRed:((Hex & 0xFF0000) >> 16)/255.0f green:((Hex & 0xFF00) >> 8)/255.0f blue:((Hex & 0xFF))/255.0f alpha:A]
与GCD相关
//只运行一次的GCD
#define DISPATCH_ONCE_BLOCK(Block) static dispatch_once_t onceToken; dispatch_once(&onceToken, Block); //在Main线程上运行的GCD
#define DISPATCH_ON_MAIN_THREAD(Block) dispatch_async(dispatch_get_main_queue(), Block); //在Global Queue上运行的GCD
#define DISPATCH_ON_GLOBAL_QUEUE_HIGH(Block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), Block);
#define DISPATCH_ON_GLOBAL_QUEUE_DEFAULT(Block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), Block);
#define DISPATCH_ON_GLOBAL_QUEUE_LOW(Block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), Block);
#define DISPATCH_ON_GLOBAL_QUEUE_BACKGROUND(Block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), Block);
与弧度、角度相关
//用角度生成弧度
#define RadiansFromDegrees(Degress) (M_PI * (Degress) / 180.0)
与UIImage相关
//获取图片资源
#define GetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
最新文章
- 这可能是由于服务终结点绑定未使用 HTTP 协议造成的 .这还可能是由于服务器中止了 HTTP 请求上下文
- iOS获取设备唯一标识的8种方法
- Linux C 中 fork() 函数详解
- 常见http status code
- runtime学习实战一:类的属性进行归档解档
- luogu[1279]字串距离
- android提示框
- iOS 库文件制作
- We&#39;re Hiring A Software Tester
- 人们的Live Meeting系列 (floyd)
- matlab 利用while循环计算平均值和方差
- 像 npm 一样在 Andriod 项目中引入 Gradle 依赖
- Linux发行版 CentOS6.5下删除分区操作
- BAT齐聚阿里安全-ASRC生态大会:呼吁联合共建网络安全白色产业链
- Android Studio 3.0+ Annotation processors must be explicitly declared now
- 关于Oracle的44951事件
- vs2017 .net core 项目调试浏览器网页闪退Bug
- redis epoll 原理梗概
- 2emq服务器压力测试(无用)
- openssl 连接 https(nginx)
热门文章
- [翻译]python3中新的字符串格式化方法-----f-string
- spring——AOP原理及源码(二)
- Web渗透基础小总结
- 深度解析互联网大厂面试难题自定义@EnableXX系列
- 动态构造任意复杂的 Linq Where 表达式
- 关于HTTP那些事
- 使用HBuilder开发移动APP
- 【每日一包0018】fecha
- JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)
- JZOJ 1774. 合并果子 (Standard IO)