/*自定义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
网友评论