//? HGBMacroConfig.h
#ifndef HGBMacroConfig_h
#define HGBMacroConfig_h
#pragma mark 屏幕尺寸
#define HSize ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)
#define HWidth ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)
#define HHeight ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)
//屏幕比例
#define HScale HWidth /750.0
#define WScale HHeight /1334.0
#define HGBNavigationBar_Height44
#pragma mark 系統版本
#ifndef HVersion
#define HVersion [[[UIDevice currentDevice] systemVersion] floatValue]//系統版本號
#endif
#pragma mark 設備
#if TARGET_OS_IPHONE? ? ? ? ? ? ? ? ? ? ? ? ? //iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR? ? ? ? ? //iPhone Simulator
#endif
#define HGBISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define HGBISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#pragma mark 應用
#define HGBApplication? ? ? ? [UIApplication sharedApplication]
#define HGBKeyWindow? ? ? ? ? [UIApplication sharedApplication].keyWindow
#define HGBAppDelegate? ? ? ? [UIApplication sharedApplication].delegate
#define HGBUserDefaults? ? ? [NSUserDefaults standardUserDefaults]
#define HGBNotificationCenter [NSNotificationCenter defaultCenter]
#define HGBAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define HGBCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#define HGBDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
#define HGBTempPath NSTemporaryDirectory()
#define HGBCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
#pragma mark ARC與非ARC實例
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
#pragma mark 引用
#define HGBWeakSelf(type)? __weak typeof(type) weak##type = type;
#define GBStrongSelf(type) __strong typeof(type) type = weak##type;
#pragma mark 程序的本地化,引用國際化的文件
#define HGBLocal(x,...) NSLocalizedString(x, nil)
#pragma mark 單例
#define HGBShareInstance(classname) static classname *shared##classname = nil; + (classname *)shared##classname{@synchronized(self) {if (shared##classname == nil){shared##classname = [self alloc] init];}} return shared##classname; } + (id)allocWithZone:(NSZone *)zone{@synchronized(self){if (shared##classname == nil){shared##classname = [super allocWithZone:zone];return shared##classname;}} return nil;} - (id)copyWithZone:(NSZone *)zone{return self; }
#pragma mark 線程
#define HGBBack(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), block)
#define HGBMain(block) dispatch_async(dispatch_get_main_queue(),block)
#pragma mark 提示
#define HGBLog(FORMAT,...) fprintf(stderr,"**********HGBErrorLog-satrt***********\n{\n文件名稱:%s;\n方法:%s;\n行數:%d;\n提示:%s\n}\n**********HGBErrorLog-end***********\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],[[NSString stringWithUTF8String:__func__] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#ifdef DEBUG
#define NSLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define NSLog(...)
#endif
#ifdef DEBUG
#? define DLog(fmt, ...) NSLog((@"%s [Line %d] "fmt), __PRETTY_FUNCTION__,__LINE__, ##__VA_ARGS__);
#else
#? define DLog(...)
#endif
#ifdef DEBUG
#define ULog(t,m) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:t message:m delegate:nil cancelButtonTitle:@"Ok"otherButtonTitles:nil]; [alert show]; }
#else
#? define ULog(...)
#endif
#pragma mark tag
#define HGBTag(object,tag)? ? [object viewWithTag : tag]
#pragma mark 角度弧度
#define HGBDegreesToRadian(x)? (M_PI*(x)/180.0)
#define HGBRadianToDegrees(radian) (radian *180.0) / (M_PI)
#pragma mark 字體大小
/**
?字體大小
?@param size 大小
?@return 字體
?*/
#define HGBFont(size) [UIFont systemFontOfSize:size]
#pragma mark 顏色
/**
?顏色
?@param r 紅色
?@param g 綠色
?@param b 藍色
?@param a 透明度
?@return 顏色
?*/
#define HGBAColor(r,g,b,a)? [UIColor colorWithRed:r/255.0green:g/255.0blue:b/255.0alpha:a]
/**
?顏色-不透明
?@param r 紅色
?@param g 綠色
?@param b 藍色
?@return 顏色
?*/
#define HGBColor(r,g,b) [UIColor colorWithRed:r/255.0green:g/255.0blue:b/255.0alpha:1]
#pragma mark 圖片
#define HGBBundleImage(name) [UIImage imageWithContentsOfFile:[NSBundle mainBundle] pathForResource:name ofType:nil]
#define HGBLoadImage(file,ext) [UIImage imageWithContentsOfFile:[NSBundle mainBundle]pathForResource:file ofType:ext]
#define HGBImage(name) [UIImage imageNamed:name]
#pragma mark 字符串
/**
?字符串去除兩端空格
?@param string 字符串
?@return 字符串
?*/
#define HGBTrim(string) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
/**
?刪除字符串空格
?@param string 字符串
?@return 字符串
?*/
#define HGBDelSpace(string) while([string containsString:@" "]){string=[string stringByReplacingOccurrencesOfString:@" "withString:@""];}
#pragma mark 判空
/**
?字符串判空
?@param string 字符串
?@return 是否為空
?*/
#define HGBStringIsEmpty(string) ([string isKindOfClass:[NSNull class]] || string == nil || [string length] <1? YES : NO )
/**
?數組判空
?@param array 數組
?@return 是否為空
?*/
#define HGBArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count ==0? YES : NO)
/**
?數組判空
?@param array 數組
?@return 是否為空
?*/
#define HGBArrayEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count ==0? YES : NO)
/**
?字典判空
?@param dictionary 字典
?@return 是否為空
?*/
#define HGBDictionaryIsEmpty(dictionary)? (dictionary == nil || [dictionary isKindOfClass:[NSNull class]] || dictionary.allKeys.count ==0? YES : NO)
/**
?對象判空
?@param object 對象
?@return 是否為空
?*/
#define HGBObjectIsEmpty(object)? (object == nil||[object isKindOfClass:[NSNull class]]||([object respondsToSelector:@selector(length)] && [(NSData *)object length] ==0)|| ([object respondsToSelector:@selector(count)] && [(NSArray *)object count] ==0)?YES:NO)
//
//? HGBMacroTool.h
//? MyApp_HGB
//
//? Created by huangguangbao on 2017/10/28.
//? Copyright ? 2017年 agree.com.cn. All rights reserved.
//
#import
#import
@interfaceHGBMacroTool : NSObject
#pragma mark 屏幕尺寸
#define HSize ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)
#define HWidth ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)
#define HHeight ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)
//屏幕比例
#define HScale HWidth /750.0
#define WScale HHeight /1334.0
#define HGBNavigationBar_Height44
#pragma mark 系統版本
#ifndef HVersion
#define HVersion [[[UIDevice currentDevice] systemVersion] floatValue]//系統版本號
#endif
#pragma mark 設備
#if TARGET_OS_IPHONE? ? ? ? ? ? ? ? ? ? ? ? ? //iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR? ? ? ? ? //iPhone Simulator
#endif
#define HGBISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define HGBISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#pragma mark 應用
#define HGBApplication? ? ? ? [UIApplication sharedApplication]
#define HGBKeyWindow? ? ? ? ? [UIApplication sharedApplication].keyWindow
#define HGBAppDelegate? ? ? ? [UIApplication sharedApplication].delegate
#define HGBUserDefaults? ? ? [NSUserDefaults standardUserDefaults]
#define HGBNotificationCenter [NSNotificationCenter defaultCenter]
#define HGBAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define HGBCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#define HGBDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
#define HGBTempPath NSTemporaryDirectory()
#define HGBCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
#pragma mark ARC與非ARC實例
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
#pragma mark 引用
#define HGBWeakSelf(type)? __weak typeof(type) weak##type = type;
#define GBStrongSelf(type) __strong typeof(type) type = weak##type;
#pragma mark 程序的本地化,引用國際化的文件
#define HGBLocal(x,...) NSLocalizedString(x, nil)
#pragma mark 單例
#define HGBShareInstance(classname) static classname *shared##classname = nil; + (classname *)shared##classname{@synchronized(self) {if (shared##classname == nil){shared##classname = [self alloc] init];}} return shared##classname; } + (id)allocWithZone:(NSZone *)zone{@synchronized(self){if (shared##classname == nil){shared##classname = [super allocWithZone:zone];return shared##classname;}} return nil;} - (id)copyWithZone:(NSZone *)zone{return self; }
#pragma mark 線程
#define HGBBack(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), block)
#define HGBMain(block) dispatch_async(dispatch_get_main_queue(),block)
#pragma mark 提示
#define HGBLog(FORMAT,...) fprintf(stderr,"**********HGBErrorLog-satrt***********\n{\n文件名稱:%s;\n方法:%s;\n行數:%d;\n提示:%s\n}\n**********HGBErrorLog-end***********\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],[[NSString stringWithUTF8String:__func__] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#ifdef DEBUG
#define NSLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define NSLog(...)
#endif
#ifdef DEBUG
#? define DLog(fmt, ...) NSLog((@"%s [Line %d] "fmt), __PRETTY_FUNCTION__,__LINE__, ##__VA_ARGS__);
#else
#? define DLog(...)
#endif
#ifdef DEBUG
#define ULog(t,m) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:t message:m delegate:nil cancelButtonTitle:@"Ok"otherButtonTitles:nil]; [alert show]; }
#else
#? define ULog(...)
#endif
#pragma mark tag
#define HGBTag(object,tag)? ? [object viewWithTag : tag]
#pragma mark 角度弧度
#define HGBDegreesToRadian(x)? (M_PI*(x)/180.0)
#define HGBRadianToDegrees(radian) (radian *180.0) / (M_PI)
#pragma mark 字體大小
/**
?字體大小
?@param size 大小
?@return 字體
?*/
#define HGBFont(size) [UIFont systemFontOfSize:size]
#pragma mark 顏色
/**
?顏色
?@param r 紅色
?@param g 綠色
?@param b 藍色
?@param a 透明度
?@return 顏色
?*/
#define HGBAColor(r,g,b,a)? [UIColor colorWithRed:r/255.0green:g/255.0blue:b/255.0alpha:a]
/**
?顏色-不透明
?@param r 紅色
?@param g 綠色
?@param b 藍色
?@return 顏色
?*/
#define HGBColor(r,g,b) [UIColor colorWithRed:r/255.0green:g/255.0blue:b/255.0alpha:1]
#pragma mark 圖片
#define HGBBundleImage(name) [UIImage imageWithContentsOfFile:[NSBundle mainBundle] pathForResource:name ofType:nil]
#define HGBLoadImage(file,ext) [UIImage imageWithContentsOfFile:[NSBundle mainBundle]pathForResource:file ofType:ext]
#define HGBImage(name) [UIImage imageNamed:name]
#pragma mark 字符串
/**
?字符串去除兩端空格
?@param string 字符串
?@return 字符串
?*/
#define HGBTrim(string) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
/**
?刪除字符串空格
?@param string 字符串
?@return 字符串
?*/
#define HGBDelSpace(string) while([string containsString:@" "]){string=[string stringByReplacingOccurrencesOfString:@" "withString:@""];}
#pragma mark 判空
/**
?字符串判空
?@param string 字符串
?@return 是否為空
?*/
#define HGBStringIsEmpty(string) ([string isKindOfClass:[NSNull class]] || string == nil || [string length] <1? YES : NO )
/**
?數組判空
?@param array 數組
?@return 是否為空
?*/
#define HGBArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count ==0? YES : NO)
/**
?數組判空
?@param array 數組
?@return 是否為空
?*/
#define HGBArrayEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count ==0? YES : NO)
/**
?字典判空
?@param dictionary 字典
?@return 是否為空
?*/
#define HGBDictionaryIsEmpty(dictionary)? (dictionary == nil || [dictionary isKindOfClass:[NSNull class]] || dictionary.allKeys.count ==0? YES : NO)
/**
?對象判空
?@param object 對象
?@return 是否為空
?*/
#define HGBObjectIsEmpty(object)? (object == nil||[object isKindOfClass:[NSNull class]]||([object respondsToSelector:@selector(length)] && [(NSData *)object length] ==0)|| ([object respondsToSelector:@selector(count)] && [(NSArray *)object count] ==0)?YES:NO)
@end
#endif /* HGBMacroConfig_h */