美文网首页
ios日常工作之常用宏定义

ios日常工作之常用宏定义

作者: 小小Q吖 | 来源:发表于2016-07-06 09:16 被阅读47次
    • 1.获取屏幕宽度与高度
    #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
    #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
    
    • 2.获取通知中心
    #define WDDNotificationCenter [NSNotificationCenter defaultCenter];
    
    • 3.设置随机颜色
    #define WDDRandomColor [UIColor colorWithRed: arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
    
    • 4.设置RGB颜色/ 设置RGBA颜色
    #define WDDRGBColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0];
    #define WDDRGBAColor(r,g,b,a) [UIColor colorWithRed:(r)/255.9 green:(g)/255.0 blue:(b)/255.0 alpha:a];
    #define WDDClearColor [UIColor clearColor];
    
    • 5.自定义高效率的 NSLog
    #ifdef DEBUG
    #define WDDLog(...) NSLog(@"%s 第%d行 \n  %@\n\n,__func__,__LINE__,[NSString stringWithFormat:__VS_ARGS__]");
    #else
    #define WDDLog(...) 
    #end if
    
    • 设置 view 圆角 和 边框
    #define WDDViewBorderRadius(View,Radius, Width ,Color)\
    \
    [View.layer setCornerRadius:(Radius)];\
    [View.layer setMasksToBounds:YES];\
    [View.layer setBorderWidth:(Width)];\
    [View.layer setBorderColor:[Color CGColor]]
    
    • 由角度转换弧度 有弧度转换角度
    #define LRDgreesToRadian(x)(M_PI * (x) / 180.0)
    #define LRRadianToDegrees(radian)(radian*180.0)/(M_PI)
    
    • 设置加载提示框 (第三方矿建 :Toast)
    此宏定义非常好用,但是小伙伴需要CocoaPods导入第三方框架:Toast
    使用方法如下:
    LRToast(@"网络加载失败");
    
    • 获取当前语言
    #define WDDCurrentLanguage ([NSLocale preferredLanguages] objectAtIndex:0])
    
    • 使用 ARC 和 MRC
    #if   __has_feature(objc_arc)
    //ARC
    #else
    //MRC
    #endif
    
    • 判断当前的Iphone设备/系统版本
    判断是否是iPhone
    #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    判断是否是ipad
    #define IS_IPAD(UI_USER_INTERDAXE_ISIOM() ==UIUserInterfaceIdiomPad)
    判断是否为 ipod
    #define IS_IPOD ([[[UIDevice currentDevice] model] isEqealToString:@"iPod touch"])
    判断是否为 iPhone 5SE
    #define iPhone5SE [[[UIScreen mainScreen].bounds].size.width == 320.0f && [UIScreen mainScreen]bounds.size.height ==568.0f
    判断是否为 iPhone 6/6s
    #define iPhone6_6s [UIScreen mainScreen].bounds].size.width == 357.0f && [[UIScreen mainScreen]bounds].size.height == 667.0f
    判断是否为 iPhone 6Plus/6sPlus
    #define iPhone6Plus_6sPlus [UIScreen mainScreen].bounds].size.width ==414.0f && [[UIScreen mainScreen]bounds].size.height == 736.0f
    获取系统版本
    #define IOS_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
    判断 iOS 8 或者 更高的 系统版本
    #define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue];
    
    • 判断是真机还是模拟器
    #if TARGET_OS_IPHONE
    //iPhone Device
    #endif
    #if TARGET_OS_SIMULATOR
    //iPhone Simulator
    #endif
    
    • 获取view的frame /图片资源
    #define wDDGetViewWidth(view)  view.frame.size.width
    #define wDDGetViewHeight(view) view.frame.size.height
    #define wDDGetViewX(view)  view.frame.origin.x
    #define wDDGetViewY(view)  view.frame.origin.y
    #define wDDGetImage(imageName) [UIImage imageNamed:[NSStringWithFormat:@"%@",imageName]]
    

    转自 【链接】判若两人丶
    http://www.jianshu.com/users/16ae66cdf6a0/latest_articles

    相关文章

      网友评论

          本文标题:ios日常工作之常用宏定义

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