美文网首页
2. 常用宏定义,会随时更新

2. 常用宏定义,会随时更新

作者: 紫竹吟风 | 来源:发表于2017-07-11 13:09 被阅读0次

    现在项目中不可或缺的就是各种宏,一下列出我经常用到的几个宏,后面还会陆续更新:

    RGB颜色:UI给出的效果图里的颜色值一般都是 0xFFFFFF 类似格式的 或者是 255,255,255 等三段模式的,其实归根结底都是一样的 只是用不同的写法来标记的,这就是需要我们在实际用的时候进行转化

    // RGB颜色
    #define CSYColor16(s)  [UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0 green:(((s &0xFF00) >>8))/255.0 blue:((s &0xFF))/255.0 alpha:1.0]
    #define CSYColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
    

    打印输出语句

    // 自定义Log
    #ifdef DEBUG
    
    #define SYLog(...) NSLog(@"%s %d \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
    #else
    #define SYLog(...)
    #endif
    
    // 自定义blog Xcode8 打印不全 所以自定义一个
    #ifdef DEBUG
    #define SLog(format, ...) printf(" %s  %d\n%s\n", __func__,__LINE__, [[NSString stringWithFormat:(format), __VA_ARGS__] UTF8String] )
    #else
    #define SLog(format, ...)
    #endif
    
    /** 当前系统版本 */
    #define kVersion  [[[UIDevice currentDevice] systemVersion] doubleValue]
    
    /** 单例 **/
    #define sharedSingletonH(className) \
    \
    + (className *)shared##className;
    
    #define sharedSingletonM(className) \
    \
    + (className *)shared##className { \
    static className *shared##className = nil; \
    static dispatch_once_t onceToken; \
    dispatch_once(&onceToken, ^{ \
    shared##className = [[self alloc] init]; \
    }); \
    return shared##className; \
    }
    
    //判断是模拟器还是真机
    #if TARGET_IPHONE_SIMULATOR
    #define SIMULATOR 1
    #elif TARGET_OS_IPHONE
    #define SIMULATOR 0
    #endif
    //获取屏幕 宽度、高度
    #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
    #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
    // 系统版本
    #define Version [[UIDevice currentDevice].systemVersion doubleValue]
    

    相关文章

      网友评论

          本文标题:2. 常用宏定义,会随时更新

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