zoukankan      html  css  js  c++  java
  • IOS 常用的宏定义(#define)

    开发中经常用到的常量定义(随时更行):

    与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]]
  • 相关阅读:
    python分包写入文件,写入固定字节内容,当包达到指定大小时继续写入新文件
    java 封装及this 用法
    [效率提升] 记一次使用工具编辑正则表达式快速输出匹配结果
    java用星星符号打印出一个直角三角形
    java按行和列进行输出数据
    java 三种循环及注意事项
    数据的运算,求和,两数求最大,三数求最大,两数是否相等
    采用位异或方式将两个变量数值调换
    今天遇到一件开心事,在eclipse编写的代码在命令窗口中编译后无法运行,提示 “错误: 找不到或无法加载主类”
    定义 java 基本数据类型
  • 原文地址:https://www.cnblogs.com/nmzd/p/4532965.html
Copyright © 2011-2022 走看看