Common.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 IS_IPAD [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3 ? (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) : [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad
  38. #define AUTO_NIB(NIB_NAME) IS_IPAD?[NSString stringWithFormat:@"%@_iPad", NIB_NAME]:IS_4INCH_SCREEN?[NSString stringWithFormat:@"%@_4Inch", NIB_NAME]:NIB_NAME
  39. //Network
  40. #define ksHTTPRequestPOST @"POST"
  41. #define ksHTTPRequestGET @"GET"
  42. #define ksHTTPRequestDELETE @"DELETE"
  43. #define ksHTTPRequestPUT @"PUT"
  44. #define kDefaultTimeOut 30
  45. #define ksHTTPMultipartForm @"MULTIPART_FORM"
  46. #define ksCustomRadioButtonObject @"RADIO_OBJECT"
  47. #define ksCustomRadioButtonStatus @"RADIO_STATUS"
  48. #define ksCustomCheckBoxStatus @"CHECK_STATUS"
  49. //COLOR
  50. #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
  51. #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
  52. //MATH
  53. #define DEGREES(radians)((radians) * 180 / M_PI)
  54. #define RADIANS(degree)((degree) * M_PI / 180)
  55. //STRING
  56. #define ksEmptyString @""
  57. //LOCALIZATION
  58. #define LocalizedString(String) NSLocalizedString((String), nil)
  59. #define RECT_X(view) view.frame.origin.x
  60. #define RECT_Y(view) view.frame.origin.y
  61. #define RECT_WIDTH(view) view.frame.size.width
  62. #define RECT_HEIGHT(view) view.frame.size.height
  63. //LOG
  64. // XCodeColors
  65. #define XCODE_COLORS_ESCAPE @"\033["
  66. #define XCODE_COLORS_RESET_FG XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color
  67. #define XCODE_COLORS_RESET_BG XCODE_COLORS_ESCAPE @"bg;" // Clear any background color
  68. #define XCODE_COLORS_RESET XCODE_COLORS_ESCAPE @";" // Clear any foreground or background color
  69. #ifdef DEBUG_MODE
  70. static const int ddLogLevel = DDLogLevelDebug;
  71. #define NSLogObj(x) DDLogDebug(@"%@", x)
  72. #define NSLogPoint(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGPoint(x))
  73. #define NSLogSize(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGSize(x))
  74. #define NSLogRect(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGRect(x))
  75. #define NSLogFunc() DDLogDebug(@"%s", __PRETTY_FUNCTION__)
  76. #define NSLogFuncObj(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, x)
  77. #define NSLog(format, ...) DDLogDebug(@"[%s(%d)] %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(format), ##__VA_ARGS__])
  78. #define SHOW_DICTIONARY_INFO(dict) {NSLog(@"***** Displaying Dictionary Information *****"); for (NSString *key in dict.allKeys) NSLog(@"[%@] : %@", key,[dict objectForKey:key]); NSLog(@"***** Finished Dictionary Information *****");}
  79. // #define NSLog(format, ...) DDLogDebug(format, ## __VA_ARGS__)
  80. // #define NSLog( s, ... ) NSLog( @"[%s(%d)] %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
  81. //NSLog( @"[%@ %s(%d)] %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
  82. #define NSLogInfo(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg0,0,200;" format XCODE_COLORS_RESET), ##__VA_ARGS__)
  83. // #define NSLog(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " format XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
  84. // #define NSLog(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " fmt XCODE_COLORS_RESET),format, ## __VA_ARGS__)
  85. #else
  86. #ifdef PRODUCT_MODE //운영모드 일 경우, 로그를 출력하지 않음
  87. static const int ddLogLevel = DDLogLevelError;
  88. #define NSLogObj(x)
  89. #define NSLogPoint(x)
  90. #define NSLogSize(x)
  91. #define NSLogRect(x)
  92. #define NSLogFunc()
  93. #define NSLogFuncObj(x)
  94. #define NSLog(format, ...)
  95. #else
  96. static const int ddLogLevel = DDLogLevelDebug;
  97. #define NSLogObj(x) DDLogDebug(@"%@", x)
  98. #define NSLogPoint(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGPoint(x))
  99. #define NSLogSize(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGSize(x))
  100. #define NSLogRect(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGRect(x))
  101. #define NSLogFunc() DDLogDebug(@"%s", __PRETTY_FUNCTION__)
  102. #define NSLogFuncObj(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, x)
  103. #define NSLog(format, ...) DDLogDebug(format, ## __VA_ARGS__)
  104. #endif
  105. #endif
  106. //// DLog
  107. //#ifdef DEBUG
  108. //#define DLog(fmt, ...) CLSNSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  109. //#define DLogError(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  110. //#define DLogWarn(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg241,196,15;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  111. //#define DLogInfo(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg26,188,156;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  112. //#else
  113. //#define DLog(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  114. //#define DLogError(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  115. //#define DLogWarn(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  116. //#define DLogInfo(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  117. //#endif
  118. #endif