YMConstMacro.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef YMConstMacro_h
  2. #define YMConstMacro_h
  3. #import <CoreGraphics/CoreGraphics.h>
  4. #define YMPath_DOCUMENT [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
  5. #define kWindow \
  6. ({\
  7. UIWindow* window = nil;\
  8. if (@available(iOS 13.0, *)) { \
  9. for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes){ \
  10. if (windowScene.activationState == UISceneActivationStateForegroundActive){ \
  11. window = windowScene.windows.firstObject; \
  12. break; \
  13. }\
  14. }\
  15. }\
  16. else { \
  17. window = [[UIApplication sharedApplication].delegate window];\
  18. }\
  19. window = [[UIApplication sharedApplication].delegate window];\
  20. (window);\
  21. })
  22. //查看程序运行位置
  23. #define CheckRunWhere NSLog(@"%s",__func__);
  24. //安全区域top
  25. #define kSafeAreaTop \
  26. ({\
  27. CGFloat top = 0.f;\
  28. if (@available(iOS 11,*)) {\
  29. top = [[[UIApplication sharedApplication] delegate] window].safeAreaInsets.top;\
  30. }\
  31. (top);\
  32. })
  33. //安全区域bottom
  34. #define kSafeAreaBottom \
  35. ({\
  36. CGFloat bottom = 0.f;\
  37. if (@available(iOS 11,*)) {\
  38. bottom = [[[UIApplication sharedApplication] delegate] window].safeAreaInsets.bottom;\
  39. }\
  40. (bottom);\
  41. })
  42. //是否iPhoneX
  43. #define ZYiPhoneX (kSafeAreaBottom > 0 ? YES : NO)
  44. //状态栏高度
  45. #define kStatusBarHeight (kSafeAreaTop > 0 ? kSafeAreaTop : 20)
  46. //navbar高度
  47. #define kNavBarHeight (44+kStatusBarHeight)
  48. //弱引用
  49. #define WS(weakSelf) __weak __typeof(&*self)weakSelf = self
  50. #ifndef kSCREEN_HEIGHT
  51. #define kSCREEN_HEIGHT (CGFloat)([[UIScreen mainScreen] bounds].size.height)
  52. #endif
  53. #ifndef kSCREEN_WIDTH
  54. #define kSCREEN_WIDTH (CGFloat)([[UIScreen mainScreen] bounds].size.width)
  55. #endif
  56. /** 参照宽高 375 * 812 **/
  57. #define KReferenceHeight 812.f
  58. #define KReferenceWidth 375.f
  59. /** 宽高比例 **/
  60. #define KScaleW (CGFloat)(kSCREEN_WIDTH/KReferenceWidth)
  61. #define KScaleH (CGFloat)(kSCREEN_HEIGHT/KReferenceHeight)
  62. #define YMUserDeafaults [NSUserDefaults standardUserDefaults]
  63. #define kMainScreenWidth [[UIScreen mainScreen] bounds].size.width
  64. #define kMainScreenHeight [[UIScreen mainScreen] bounds].size.height
  65. #define DEFAULT_CHANNEL_ID [YMUtil channelId]
  66. #define YMMainScreenScale [UIScreen mainScreen].scale
  67. #define ImageName(X) (UIImage*)([UIImage imageNamed:X])
  68. #define YMBoundRect(string,maxWidth,font) [string boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil]
  69. #define YMBoundWidth(string,font) [string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil]
  70. #define SLColor(X) (UIColor*)([UIColor colorFormString:X])
  71. //WeakSelf
  72. #define WEAKSELF typeof(self) __weak wkSelf = self;
  73. ///
  74. #define StrongWeakSelf typeof(wkSelf) __strong stSelf=wkSelf;
  75. #define SLBgColor SLColor(@"#F2F3F7")
  76. #define SLBlackColor SLColor(@"#273F66")
  77. #define SLBlueColor SLColor(@"#1677FF")
  78. #define SLBlueSelColor SLColor(@"#0052D9")
  79. #define SL333Color SLColor(@"#333333")
  80. #endif /* YMConstMacro_h */