• 一些宏


    dealloc里面释放对象

    #if DEBUG  
    #define MCRelease(x) [x release]  
    #else  
    #define MCRelease(x) [x release], x = nil  
    #endif 
    复制代码
    //use dlog to print while in debug model
    #ifdef DEBUG
    #   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
    #else
    #   define DLog(...)
    #endif
    复制代码

    在不同系统区分代码

    复制代码
    #ifdef __IPHONE_5_0
        float version = [[[UIDevice currentDevice] systemVersion] floatValue];
        if (version >= 5.0) {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil];
        }
    #endif
    复制代码

    系统信息

    复制代码
    #define NavigationBar_HEIGHT 44
     
    #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
    #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
    #define SAFE_RELEASE(x) [x release];x=nil
    #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
    #define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])  
    #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) 
    复制代码

    设备

    复制代码
    #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
    #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
    #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
     
     
    #if TARGET_OS_IPHONE
    //iPhone Device
    #endif
     
    #if TARGET_IPHONE_SIMULATOR
    //iPhone Simulator
    #endif
    复制代码

    RGB颜色

    #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
    #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
    #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]

    ARC监测

    //ARC
    #if __has_feature(objc_arc)
        //compiling with ARC
    #else
        // compiling without ARC
    #endif

    度,弧度

    #pragma mark - degrees/radian functions 
    #define degreesToRadian(x) (M_PI * (x) / 180.0)
    #define radianToDegrees(radian) (radian*180.0)/(M_PI)

    RGB颜色转换(16进制->10进制)

    #define UIColorFromRGB(rgbValue)  [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

    定义CGRECT

    #define CGRectMake(a,b,c,d)  CGRectMake((a)/320.0*[[UIScreen mainScreen] applicationFrame].size.width,(b)/460.0*[[UIScreen mainScreen] applicationFrame].size.height,(c)/320.0*[[UIScreen mainScreen] applicationFrame].size.width,(d)/460.0*[[UIScreen mainScreen] applicationFrame].siz

    weak,strong

    1
    2
    #define WEAKSELF typeof(self) __weak weakSelf = self;
    #define STRONGSELF typeof(weakSelf) __strong strongSelf = weakSelf;
    复制代码
    //6.0一下兼容6.0枚举类型,避免版本导致的警告
    #define UILineBreakMode                 NSLineBreakMode
    #define UILineBreakModeWordWrap            NSLineBreakByWordWrapping
    #define UILineBreakModeCharacterWrap    NSLineBreakByCharWrapping
    #define UILineBreakModeClip                NSLineBreakByClipping
    #define UILineBreakModeHeadTruncation    NSLineBreakByTruncatingHead
    #define UILineBreakModeTailTruncation    NSLineBreakByTruncatingTail
    #define UILineBreakModeMiddleTruncation    NSLineBreakByTruncatingMiddle
    
    #define UITextAlignment                 NSTextAlignment
    #define UITextAlignmentLeft                NSTextAlignmentLeft
    #define UITextAlignmentCenter            NSTextAlignmentCenter
    #define UITextAlignmentRight            NSTextAlignmentRight
    复制代码

     版本兼容

    复制代码
    #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
    #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
    #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
    复制代码
  • 相关阅读:
    跨域
    关于DEDECMS自定义模型当中添加自定义字段后在后台添加内容后不显示解决方案
    js复制文本
    dedecms 织梦显示时间格式
    基本特效:饿了么丝滑无缝过度搜索栏的实现
    2016-wing的年度总结
    这交互炸了(四) :一分钟让你拥有微信拖拽透明返回PhotoView
    这交互炸了(三):闪屏页是像云一样消失的
    这交互炸了(二):爱范儿是如何让详情页缩小为横向列表的
    这交互炸了:饿了么是怎么让Image变成详情页的
  • 原文地址:https://www.cnblogs.com/lingzhao/p/3487349.html
Copyright © 2020-2023  润新知