zoukankan      html  css  js  c++  java
  • ios-常用宏

    #ifndef PrefixHeader_pch
    #define PrefixHeader_pch
    
    //共同方法
    #import "Common.h"
    
    #ifdef DEBUG
    #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
    #else
    #define DLog(...)
    #endif
    
    
    //弱引用/强引用
    #define LRWeakSelf(type)  __weak typeof(type) weak##type = type;
    #define LRStrongSelf(type)  __strong typeof(type) type = weak##type;
    
    
    #define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width
    #define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height
    
    
    //字典非空判断
    #define MySetValue(dict, value) ((!dict[value] || [dict[value] isKindOfClass:[NSNull class]])?@"":dict[value])
    
    
    
    //获取通知
    #define LRNotificationCenter [NSNotificationCenter defaultCenter]
    //随机颜色
    #define LRRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
    
    //RGB
    #define LRRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
    #define LRRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
    // clear背景颜色
    #define LRClearColor [UIColor clearColor]
    
    
    #ifdef DEBUG
    #define LRLog(...) NSLog(@"%s 第%d行 
     %@
    
    ",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
    #else
    #define LRLog(...)
    #endif
    
    
    //空间 圆角、边宽、颜色
    #define LRViewBorderRadius(View, Radius, Width, Color)
    
    [View.layer setCornerRadius:(Radius)];
    [View.layer setMasksToBounds:YES];
    [View.layer setBorderWidth:(Width)];
    [View.layer setBorderColor:[Color CGColor]]
    
    
    //判断是否为iPhone
    #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    //判断是否为iPad
    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    //判断是否为ipod
    #define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"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 == 375.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]
    
    //获取temp
    #define kPathTemp NSTemporaryDirectory()
    //获取沙盒 Document
    #define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
    //获取沙盒 Cache
    #define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
    
    //GCD - 一次性执行
    #define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);
    //GCD - 在Main线程上运行
    #define kDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);
    //GCD - 开启异步线程
    #define kDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);
    
    
    #endif /* PrefixHeader_pch */
  • 相关阅读:
    求一列的和,awk和perl哪个快?
    转:使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制
    使用apt-get autoremove造成的系统无法开机
    因不公对待,技术销毁删除代码数据,谁对谁错?负能量文章,老板慎入。
    我曾经做过的插件
    宝石TD迷宫设计器
    VSX-5 VSXMusic 编码听音乐
    耐得住寂寞,才能守得住繁华
    VSX-4 VSXTra
    VSX-3 VSCT文件
  • 原文地址:https://www.cnblogs.com/sayimba/p/6265967.html
Copyright © 2011-2022 走看看