Common.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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(format, ## __VA_ARGS__)
  78. #define NSLogInfo(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg0,0,200;" format XCODE_COLORS_RESET), ##__VA_ARGS__)
  79. // #define NSLog(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " format XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
  80. // #define NSLog(format, ...) DDLogDebug((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " fmt XCODE_COLORS_RESET),format, ## __VA_ARGS__)
  81. #else
  82. #ifdef PRODUCT_MODE //운영모드 일 경우, 로그를 출력하지 않음
  83. static const int ddLogLevel = DDLogLevelError;
  84. #define NSLogObj(x)
  85. #define NSLogPoint(x)
  86. #define NSLogSize(x)
  87. #define NSLogRect(x)
  88. #define NSLogFunc()
  89. #define NSLogFuncObj(x)
  90. #define NSLog(format, ...)
  91. #else
  92. static const int ddLogLevel = DDLogLevelDebug;
  93. #define NSLogObj(x) DDLogDebug(@"%@", x)
  94. #define NSLogPoint(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGPoint(x))
  95. #define NSLogSize(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGSize(x))
  96. #define NSLogRect(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, NSStringFromCGRect(x))
  97. #define NSLogFunc() DDLogDebug(@"%s", __PRETTY_FUNCTION__)
  98. #define NSLogFuncObj(x) DDLogDebug(@"%s, %@", __PRETTY_FUNCTION__, x)
  99. #define NSLog(format, ...) DDLogDebug(format, ## __VA_ARGS__)
  100. #endif
  101. #endif
  102. //// DLog
  103. //#ifdef DEBUG
  104. //#define DLog(fmt, ...) CLSNSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  105. //#define DLogError(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg231,76,60;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  106. //#define DLogWarn(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg241,196,15;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  107. //#define DLogInfo(fmt, ...) CLSNSLog((XCODE_COLORS_ESCAPE @"fg26,188,156;%s[Line %d] " fmt XCODE_COLORS_RESET), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  108. //#else
  109. //#define DLog(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  110. //#define DLogError(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  111. //#define DLogWarn(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  112. //#define DLogInfo(fmt, ...) CLSLog((@"%s[Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
  113. //#endif
  114. #endif