• 一些宏


    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)
    复制代码
  • 相关阅读:
    Spring bean的实例化
    提交本地代码到github
    ORM框架——SQLAlchemy
    代码发布项目(三)——python操作git、代码发布流程(服务器管理、项目管理)
    代码发布项目(二)——django实现websocket(使用channels)、基于channels实现群聊功能、gojs插件、paramiko模块
    代码发布项目(一)——实现服务端主动给客户端推送消息(websocket)
    索引补充(索引种类,正确使用索引,其他注意事项,慢日志查询)
    mysql索引种类(索引种类和建立索引)
    centos6安装Docker遇到的问题(升级centos6内核)
    Django1.11下载安装xadmin
  • 原文地址:https://www.cnblogs.com/lingzhao/p/3487349.html
Copyright © 2020-2023  润新知