Common.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // Common.h
  3. // kneet2
  4. //
  5. // Created by Created by Jason Lee on 10/1/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #ifndef kneet2_Common_h
  9. #define kneet2_Common_h
  10. //iphone window
  11. //320 x 480 pts 320 x 568 pts 375 x 667 pts 414 x 736 pts
  12. //ipad
  13. //1024x768 1024x768
  14. #define STATUS_BAR_HEIGHT [UIApplication sharedApplication].statusBarFrame.size.height
  15. #define IPHONE_WIDTH [UIScreen mainScreen].bounds.size.width
  16. #define IPHONE_HEIGHT [[UIScreen mainScreen] bounds].size.height
  17. #define IPHONE_NAVIGATIONBAR_HEIGHT 65
  18. #define IPHONE_MARGIN_BOTTOM 49
  19. #define SEARCHBAR_HEIGHT 44
  20. #define PORTRAIT_KEYBOARD_HEIGHT 216
  21. #define LANDSCAPE_KEYBOARD_HEIGHT 162
  22. #define KEYBOARD_ACCESSORY_HEIGHT 44
  23. #define KEYBOARD_PREDICTS_HEIGHT ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.000000 ? 40 : 0)
  24. #define CGRectCenter(rect) CGRectMake((rect.size.width / 2.0f), (rect.size.height / 2.0f), rect.size.width, rect.size.height)
  25. #define CGRectCenterPos(rect) CGRectMake(rect.origin.x + (rect.size.width / 2.0f), rect.origin.y + (rect.size.height / 2.0f), rect.size.width, rect.size.height)
  26. //DEVICE
  27. #define DEVICE_MODEL [[UIDevice currentDevice] localizedModel]
  28. #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
  29. #define kfAnimationDur [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.000000 ? 0.25f : 0.3f
  30. //UI
  31. #define IS_RETINA ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))
  32. #define IS_4INCH_SCREEN CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(320, 568)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(568, 320))
  33. #define IS_35INCH_SCREEN CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(320, 480)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(480, 320))
  34. #define IS_IPHONE_5 CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(320, 568)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(568, 320))
  35. #define IS_IPHONE_6 CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(375, 667.0f)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(667.0f, 375))
  36. #define IS_IPHONE_6P CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(414, 736.0f)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(736.0f, 414))
  37. #define BOOLToString(b) ((b) ? @"YES" : @"NO")
  38. #define USERDEFAULT [NSUserDefaults standardUserDefaults]
  39. #define SharedApplication [UIApplication sharedApplication]
  40. #define Bundle [NSBundle mainBundle]
  41. #define MainScreen [UIScreen mainScreen]
  42. #define BundleInfo [Bundle infoDictionary]
  43. #define AppVersion [BundleInfo objectForKey:@"CFBundleVersion"]
  44. #define DeviceLangCode [[NSLocale preferredLanguages] objectAtIndex: 0] //시스템 언어정보 코드
  45. #define ViewWidth(v) v.frame.size.width
  46. #define ViewHeight(v) v.frame.size.height
  47. #define ViewX(v) v.frame.origin.x
  48. #define ViewY(v) v.frame.origin.y
  49. #define ViewRectSetXY(v, x, y) CGRectMake(x, y, ViewWidth(v), ViewHeight(v))
  50. #define ViewRectSetX(v, x) CGRectMake(x, ViewY(v), ViewWidth(v), ViewHeight(v))
  51. #define ViewRectSetY(v, y) CGRectMake(ViewX(v), y, ViewWidth(v), ViewHeight(v))
  52. #define RectMake(x, y, w, h) CGRectMake(x, y, w, h)
  53. #define RectX(f) f.origin.x
  54. #define RectY(f) f.origin.y
  55. #define RectWidth(f) f.size.width
  56. #define RectHeight(f) f.size.height
  57. #define RectSetWidth(f, w) CGRectMake(RectX(f), RectY(f), w, RectHeight(f))
  58. #define RectSetHeight(f, h) CGRectMake(RectX(f), RectY(f), RectWidth(f), h)
  59. #define RectSetX(f, x) CGRectMake(x, RectY(f), RectWidth(f), RectHeight(f))
  60. #define RectSetY(f, y) CGRectMake(RectX(f), y, RectWidth(f), RectHeight(f))
  61. #define RectSetSize(f, w, h) CGRectMake(RectX(f), RectY(f), w, h)
  62. #define RectSetOrigin(f, x, y) CGRectMake(x, y, RectWidth(f), RectHeight(f))
  63. #define getCenter(v) CGPointMake(v.center.x-ViewX(v), v.center.y-ViewY(v))
  64. #define SizeToStr(v) NSStringFromCGSize(v)
  65. #define FrameToStr(v) NSStringFromCGRect(v)
  66. #define IS_IPAD [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3 ? (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) : [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad
  67. #define AUTO_NIB(NIB_NAME) IS_IPAD?[NSString stringWithFormat:@"%@_iPad", NIB_NAME]:IS_4INCH_SCREEN?[NSString stringWithFormat:@"%@_4Inch", NIB_NAME]:NIB_NAME
  68. #define WEEKDAY(i) [WEEKDAYS objectAtIndex:i]
  69. //Network
  70. #define ksHTTPRequestPOST @"POST"
  71. #define ksHTTPRequestGET @"GET"
  72. #define ksHTTPRequestDELETE @"DELETE"
  73. #define ksHTTPRequestPUT @"PUT"
  74. #define kDefaultTimeOut 30
  75. #define ksHTTPMultipartForm @"MULTIPART_FORM"
  76. #define ksCustomRadioButtonObject @"RADIO_OBJECT"
  77. #define ksCustomRadioButtonStatus @"RADIO_STATUS"
  78. #define ksCustomCheckBoxStatus @"CHECK_STATUS"
  79. //COLOR
  80. #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
  81. #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
  82. #define setColor(str) [CommonUtil convertFromRGBToUIColor:str]
  83. //MATH
  84. #define DEGREES(radians)((radians) * 180 / M_PI)
  85. #define RADIANS(degree)((degree) * M_PI / 180)
  86. //STRING
  87. #define ksEmptyString @""
  88. #define EQUALS(text1, text2) [[text1 uppercaseString] isEqualToString:[text2 uppercaseString]]
  89. //LOCALIZATION
  90. #define LocalizedString(String) NSLocalizedString((String), nil)
  91. #define RECT_X(view) view.frame.origin.x
  92. #define RECT_Y(view) view.frame.origin.y
  93. #define RECT_WIDTH(view) view.frame.size.width
  94. #define RECT_HEIGHT(view) view.frame.size.height
  95. //LOG
  96. // XCodeColors
  97. #define XCODE_COLORS_ESCAPE @"\033["
  98. #define XCODE_COLORS_RESET_FG XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color
  99. #define XCODE_COLORS_RESET_BG XCODE_COLORS_ESCAPE @"bg;" // Clear any background color
  100. #define XCODE_COLORS_RESET XCODE_COLORS_ESCAPE @";" // Clear any foreground or background color
  101. #define CASE(str) if ([__s__ isEqualToString:(str)])
  102. #define SWITCH(s) for (NSString *__s__ = (s); ; )
  103. #define DEFAULT
  104. #import "CommonUtil.h"
  105. #ifdef DEBUG_MODE
  106. static const int ddLogLevel = DDLogLevelDebug;
  107. #define NSLogObj(x) DDLogDebug(@"%@", x)
  108. #define NSLogPoint(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGPoint(x))
  109. #define NSLogSize(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGSize(x))
  110. #define NSLogRect(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGRect(x))
  111. #define NSLogFunc() DDLogDebug(@"%s", __PRETTY_FUNCTION__)
  112. #define NSLogFuncObj(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, x)
  113. #define NSLog(format, ...) DDLogDebug(@"[%s(%d)] %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(format), ##__VA_ARGS__])
  114. #define SHOW_DICTIONARY_INFO(dict) {NSLog(@"***** Displaying Dictionary Information *****"); for (NSString *key in dict.allKeys) NSLog(@"[%@] : %@", key,[dict objectForKey:key]); NSLog(@"***** Finished Dictionary Information *****");}
  115. // #define NSLog(format, ...) DDLogDebug(format, ## __VA_ARGS__)
  116. // #define NSLog( s, ... ) NSLog( @"[%s(%d)] %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
  117. //NSLog( @"[%@ %s(%d)] %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
  118. #define NSLogInfo(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg0,0,200;" format XCODE_COLORS_RESET), ##__VA_ARGS__)
  119. // #define NSLog(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " format XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
  120. // #define NSLog(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " fmt XCODE_COLORS_RESET),format, ## __VA_ARGS__)
  121. #else
  122. #ifdef PRODUCT_MODE //운영모드 일 경우, 로그를 출력하지 않음
  123. static const int ddLogLevel = DDLogLevelError;
  124. #define NSLogObj(x)
  125. #define NSLogPoint(x)
  126. #define NSLogSize(x)
  127. #define NSLogRect(x)
  128. #define NSLogFunc()
  129. #define NSLogFuncObj(x)
  130. #define NSLog(format, ...)
  131. #define SHOW_DICTIONARY_INFO(dict)
  132. #else
  133. static const int ddLogLevel = DDLogLevelDebug;
  134. #define NSLogObj(x) DDLogDebug(@"%@", x)
  135. #define NSLogPoint(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGPoint(x))
  136. #define NSLogSize(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGSize(x))
  137. #define NSLogRect(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGRect(x))
  138. #define NSLogFunc() DDLogDebug(@"%s", __PRETTY_FUNCTION__)
  139. #define NSLogFuncObj(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, x)
  140. #define NSLog(format, ...) DDLogDebug(format, ## __VA_ARGS__)
  141. #define SHOW_DICTIONARY_INFO(dict) {NSLog(@"***** Displaying Dictionary Information *****"); for (NSString *key in dict.allKeys) NSLog(@"[%@] : %@", key,[dict objectForKey:key]); NSLog(@"***** Finished Dictionary Information *****");}
  142. #endif
  143. #endif
  144. //// DLog
  145. //#ifdef DEBUG
  146. //#define DLog(fmt, ...) CLSNSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  147. //#define DLogError(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  148. //#define DLogWarn(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg241,196,15;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  149. //#define DLogInfo(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg26,188,156;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  150. //#else
  151. //#define DLog(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  152. //#define DLogError(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  153. //#define DLogWarn(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  154. //#define DLogInfo(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  155. //#endif
  156. #endif