美文网首页
常用的PCH文件文件

常用的PCH文件文件

作者: Boxzhi | 来源:发表于2016-10-19 11:25 被阅读24次

/*自定义Log*/
#define ZMCFunc ZMCLog(@"%s",__func__)

// 调试
#ifdef DEBUG
#define CHANNEL             @"Test"
#define ZMCLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
// 发布
#define ZMCLog(...)
#define CHANNEL             @"AppStore"
#endif

// 屏幕宽高
#define ScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define ScreenHeight ([UIScreen mainScreen].bounds.size.height)

// 机型判断
#define iPhone5 (SCREEN_HEIGHT == 568)
#define iPhone6 (SCREEN_HEIGHT == 667)
#define iPhone6p (SCREEN_HEIGHT == 736)

// 十六进制颜色转UIColor
#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]

// 获得RGB颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)

// 警告框
#define ShowAlert(title,msg)  [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"我知道了" otherButtonTitles:nil, nil] show];

// 字符串是否为空
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
// 数组是否为空
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
// 字典是否为空
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
// 是否是空对象
#define kObjectIsEmpty(_object) (_object == nil \|| [_object isKindOfClass:[NSNull class]] \|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

// NSUserDefaults 实例化
#define USER_DEFAULT  [NSUserDefaults standardUserDefaults]
// 存储对象
#define UserDefaultSetObjectForKey(__VALUE__,__KEY__) \
{\
[USER_DEFAULT setObject:__VALUE__ forKey:__KEY__];\
[USER_DEFAULT synchronize];\
}
// 获得存储的对象
#define UserDefaultObjectForKey(__KEY__)  [USER_DEFAULT objectForKey:__KEY__]
// 删除对象
#define UserDefaultRemoveObjectForKey(__KEY__) \
{\
[USER_DEFAULT removeObjectForKey:__KEY__];\
[USER_DEFAULT synchronize];\
}

// 判断是否为V以上系统
#define IOS(V) [[[UIDevice currentDevice] systemVersion] floatValue] >= V

// App版本号
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary]objectForKey:@"CFBundleShortVersionString"]

/**
 *  判断系统版本
 */
/** 系统版本号 */
#define IOS_VERSION [[UIDevice currentDevice] systemVersion]
/** 是否为iOS7 */
#define iOS7 (([[UIDevice currentDevice] systemVersion] >= 7.0) ? YES : NO)
/** 是否为iOS8 */
#define iOS8 (([[UIDevice currentDevice] systemVersion] >= 8.0) ? YES : NO)
/** 是否为iOS9 */
#define iOS9 (([[UIDevice currentDevice] systemVersion] >= 9.0) ? YES : NO)
/** 是否为iOS10 */
#define iOS10 (([[UIDevice currentDevice] systemVersion] >= 10.0) ? YES : NO)

// 设置View圆角和边框
#define ZMCViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
// 设置View圆角
#define ZMCViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

// View 坐标(x,y)和宽高(width,height)
#define ViewxPos(v)                 (v).frame.origin.x
#define ViewyPos(v)                 (v).frame.origin.y
#define ViewWidth(v)                (v).frame.size.width
#define ViewHeight(v)               (v).frame.size.height

#define MinFrameX(v)                 CGRectGetMinX((v).frame)
#define MinFrameY(v)                 CGRectGetMinY((v).frame)

#define MidFrameX(v)                 CGRectGetMidX((v).frame)
#define MidFrameY(v)                 CGRectGetMidY((v).frame)

#define MaxFrameX(v)                 CGRectGetMaxX((v).frame)
#define MaxFrameY(v)                 CGRectGetMaxY((v).frame)

// 设置图片
#define IMAGENAMED(NAME) [UIImage imageNamed:NAME]

// 读取本地图片
#define Load_Image(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

// 字体大小
#define FONTSIZE(SIZE) [UIFont systemFontOfSize:SIZE]

// 强弱引用
#define Weakify(type)  __weak typeof(type) weak##type = type;
#define ZMCWeakSelf __weak typeof(self) weakSelf = self;

#define Strongfy(type)  __strong typeof(type) type = weak##type;

// 获得主Window
#define KeyWindow [UIApplication sharedApplication].keyWindow

// 提示Toast
#define ZMCToast(str)  CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle]; \
[KeyWindow  makeToast:str duration:1.5 position:CSToastPositionCenter style:style];\
KeyWindow.userInteractionEnabled = NO; \
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{\
KeyWindow.userInteractionEnabled = YES;\
});\

/**
 *  获取文件路径
 */
#define Path_Temp NSTemporaryDirectory()  // 获取temp
#define Path_Document [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]  // 获取沙盒 Document
#define Path_Cache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]   // 获取沙盒 Cache

/**
 *  请求成功或失败消息
 */
#define Err_code_Success IntegerValue(response[@"err_code"]) == 0
#define Err_code_20002 IntegerValue(response[@"err_code"]) == 20002
#define ShowErr_msg [HZHUDView showFailureText:response[@"err_msg"]]

#define Total_pages(value) value.result.total_pages

/**
 *  数据类型转换
 */
#define IntegerValue(value) [value integerValue]
#define NSIntegerToNsstring(value) [NSString stringWithFormat:@"%ld", value]
#define NsstringToNsInteger(value) [value intValue]

/**
 *  GCD宏定义
 */
//GCD - 一次性执行
#define DISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);
//GCD - 在Main线程上运行
#define DISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);
//GCD - 开启异步线程
#define DISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);

// 获取沙盒Document路径
#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒temp路径
#define kTempPath NSTemporaryDirectory()
//获取沙盒Cache路径
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//真机
#endif
#if TARGET_IPHONE_SIMULATOR
//模拟器
#endif

相关文章

  • iOS pch文件配置

    首先pch文件是什么? 预编译头文件的拓展名是.pch,所以又称为pch文件,该文件在项目工程中主要作用于将较常用...

  • 常用的PCH

    常用的PCH pch头文件的内容能被项目中的其他所有源文件共享和访问 ** 注意: PCH文件的特点, 项目中的所...

  • 常用的PCH文件文件

  • pch文件

    pch文件可用于在倒入常用文件,避免在不同的文件中手动导入,在Xcode6之后苹果去掉了pch文件,不过我们编程的...

  • PCH文件

    pch文件可用于在倒入常用文件,避免在不同的文件中手动导入,在Xcode6之后苹果去掉了pch文件,不过我们编程的...

  • iOS开发--PCH文件的使用

    关于pch文件的使用 pch文件在工程中经常用到,首先先介绍下pch文件的作用:1.存放一些全局的宏(整个项目中都...

  • 常用PCH文件

    愿编程让这个世界更美好

  • IOS开发框架搭建--添加pch预处理文件

    .pch文件即预编译头文件,可以用于引入一下常用的.h头文件的引用。编译器就会自动的将pch文件中的头文件添加到所...

  • ios pch 文件笔记

    文件作用 pch后缀文件主要是解决某一个常用文件需要频繁在不同的类中使用而需要经常导入的问题,使用了pch文件之后...

  • Xcode8工程支持PCH

    PCH介绍 PCH文件,是一个预编译文件,常用来处理头文件引用,宏定义等。开发过程中,一般将整个工程都使用的头文件...

网友评论

      本文标题:常用的PCH文件文件

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