iOS 常用的宏定义

    xiaoxiao2022-07-15  172

    长期更新维护

    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

    最新回复(0)