常用宏定義

//? 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 */

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,461評論 6 532
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,538評論 3 417
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,423評論 0 375
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,991評論 1 312
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,761評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,207評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,268評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,419評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,959評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,782評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,983評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,528評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,222評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,653評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,901評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,678評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,978評論 2 374

推薦閱讀更多精彩內容

  • iOS開發過程中,使用的一些常用宏定義 字符串是否為空#define kStringIsEmpty(str) ([...
    goyohol閱讀 5,373評論 30 85
  • ifndef MacroDefinition_h define MacroDefinition_h //-----...
    灰客閱讀 367評論 0 0
  • #ifndef MacroDefinition_h #define MacroDefinition_h //---...
    hushing閱讀 13,352評論 0 24
  • [轉自:iOS常用宏定義][http://www.cocoachina.com/ios/20161207/1831...
    MMOTE閱讀 725評論 3 3
  • 我是個全職媽媽。有孩子后我一直都是圍著孩子轉,完全沒有自己的時間,沒有時間參加同學聚會,沒有時間和朋友逛街,沒有時...
    胖胖豬的故事閱讀 794評論 1 1