PBDefines.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #import <Availability.h>
  2. #ifndef __IPHONE_5_0
  3. #warning "This project uses features only available in iOS SDK 5.0 and later."
  4. #endif
  5. #ifdef __OBJC__
  6. @import UIKit;
  7. @import Foundation;
  8. @import Masonry;
  9. #import "CMWarnHUD.h"
  10. #import <PBSDK/PBNetwork.h>
  11. #import <PBSDK/PBLogLocalTools.h>
  12. #endif
  13. #define WeakSelf __weak __typeof(&*self)weakSelf = self;
  14. #define W [UIScreen mainScreen].bounds.size.width/375.0
  15. #define screenWidth [UIScreen mainScreen].bounds.size.width
  16. #define screenHeight [UIScreen mainScreen].bounds.size.height
  17. #define rgba(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
  18. #define safeBarHeight [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top
  19. #define safeBottomHeight [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.bottom
  20. #define UIFONT(key) [UIFont systemFontOfSize:(key)]
  21. #define UIBOLDFONT(key) [UIFont boldSystemFontOfSize:(key)]
  22. #define SafeBlock(BlockName, ...) ({ !BlockName ? nil : BlockName(__VA_ARGS__); })
  23. #ifndef __OPTIMIZE__
  24. #define NSLog(format,...) fprintf(stderr, "时间:%s %s\n", __TIME__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])
  25. #else
  26. #define NSLog(...) NSLog(@"")
  27. #endif
  28. #define kWeakSelf(type) __weak typeof(type) weak##type = type;
  29. #define kStrongSelf(type) __strong typeof(type) type = weak##type;
  30. #define kSafeBottomMargin \
  31. ({CGFloat safeBottomMargin = 0; \
  32. if (@available(iOS 11.0, *)) { \
  33. UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window]; \
  34. safeBottomMargin = keyWindow.safeAreaInsets.bottom; \
  35. } \
  36. (safeBottomMargin); \
  37. })
  38. #define kSafeTopMargin \
  39. ({CGFloat safeTopMargin = 0; \
  40. if (@available(iOS 11.0, *)) { \
  41. UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window]; \
  42. safeTopMargin = keyWindow.safeAreaInsets.top; \
  43. } \
  44. (safeTopMargin); \
  45. })
  46. #define kSafeRightMargin \
  47. ({CGFloat safeBottomMargin = 0; \
  48. if (@available(iOS 11.0, *)) { \
  49. UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window]; \
  50. safeBottomMargin = keyWindow.safeAreaInsets.right; \
  51. } \
  52. (safeBottomMargin); \
  53. })
  54. #define kSafeLeftMargin \
  55. ({CGFloat safeBottomMargin = 0; \
  56. if (@available(iOS 11.0, *)) { \
  57. UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window]; \
  58. safeBottomMargin = keyWindow.safeAreaInsets.left; \
  59. } \
  60. (safeBottomMargin); \
  61. })