美文网首页IOS积累
iOS 常用的宏定义

iOS 常用的宏定义

作者: XY_Coder | 来源:发表于2018-05-09 14:34 被阅读1次

    长期更新维护

    1、防止循环调用的weak、strong
    #if DEBUG
    #if __has_feature(objc_arc)
    #define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
    #else
    #define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
    #endif
    #else
    #if __has_feature(objc_arc)
    #define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
    #else
    #define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
    #endif
    #endif
    #endif
    
    #ifndef strongify
    #if DEBUG
    #if __has_feature(objc_arc)
    #define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
    #else
    #define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
    #endif
    #else
    #if __has_feature(objc_arc)
    #define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
    #else
    #define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
    #endif
    #endif
    #endif
    
    2、屏幕尺寸和iPhone X适配导航高度
    #define KMAINSCREEN [UIScreen mainScreen].bounds.size
    #define kIsIPhoneX (KMAINSCREEN.width == 375.f && KMAINSCREEN.height == 812.f)
    #define kStatusBarAndNavigationBarHeight (kIs_iPhoneX ? 88.f : 64.f)
    
    3、设置RGB颜色/设置RGBA颜色
    #define XYRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
    #define XYRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
    #define XYRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
    
    4、根据iphone6 的设计稿计算缩放高度
    #define KIPhone6Space(designSpace) ((designSpace)*(KMAINSCREEN.width/667.0f)) 
    
    5、沙盒目录路径
    #define PathTemp NSTemporaryDirectory()//获取temp
    #define PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]//获取沙盒 Document
    #define PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]//获取沙盒 Cache
    

    版权印为您的作品印上版权33886871

    相关文章

      网友评论

        本文标题:iOS 常用的宏定义

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