BRPickerViewMacro.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // BRPickerViewMacro.h
  3. // BRPickerViewDemo
  4. //
  5. // Created by renbo on 2018/4/23.
  6. // Copyright © 2018 irenb. All rights reserved.
  7. //
  8. // 最新代码下载地址:https://github.com/91renb/BRPickerView
  9. #ifndef BRPickerViewMacro_h
  10. #define BRPickerViewMacro_h
  11. #import <UIKit/UIKit.h>
  12. // 底部安全区域高度
  13. #define BR_BOTTOM_MARGIN \
  14. ({CGFloat safeBottomHeight = 0;\
  15. if (@available(iOS 11.0, *)) {\
  16. safeBottomHeight = BRGetKeyWindow().safeAreaInsets.bottom;\
  17. }\
  18. (safeBottomHeight);})
  19. // 静态库中编写 Category 时的便利宏,用于解决 Category 方法从静态库中加载需要特别设置的问题
  20. #ifndef BRSYNTH_DUMMY_CLASS
  21. #define BRSYNTH_DUMMY_CLASS(_name_) \
  22. @interface BRSYNTH_DUMMY_CLASS_ ## _name_ : NSObject @end \
  23. @implementation BRSYNTH_DUMMY_CLASS_ ## _name_ @end
  24. #endif
  25. // 打印错误日志
  26. #ifdef DEBUG
  27. #define BRErrorLog(...) NSLog(@"reason: %@", [NSString stringWithFormat:__VA_ARGS__])
  28. #else
  29. #define BRErrorLog(...)
  30. #endif
  31. /** RGB颜色(16进制) */
  32. static inline UIColor *BR_RGB_HEX(uint32_t rgbValue, CGFloat alpha) {
  33. return [UIColor colorWithRed:((CGFloat)((rgbValue & 0xFF0000) >> 16)) / 255.0
  34. green:((CGFloat)((rgbValue & 0xFF00) >> 8)) / 255.0
  35. blue:((CGFloat)(rgbValue & 0xFF)) / 255.0
  36. alpha:(alpha)];
  37. }
  38. /** 获取 keyWindow */
  39. static inline UIWindow *BRGetKeyWindow(void) {
  40. UIWindow *keyWindow = nil;
  41. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 // 编译时检查SDK版本(兼容不同版本的Xcode,防止编译报错)
  42. if (@available(iOS 13.0, *)) { // 运行时检查系统版本(兼容不同版本的系统,防止运行报错)
  43. NSSet<UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
  44. for (UIScene *scene in connectedScenes) {
  45. if (scene.activationState == UISceneActivationStateForegroundActive && [scene isKindOfClass:[UIWindowScene class]]) {
  46. UIWindowScene *windowScene = (UIWindowScene *)scene;
  47. for (UIWindow *window in windowScene.windows) {
  48. if (window.isKeyWindow) {
  49. keyWindow = window;
  50. break;
  51. }
  52. }
  53. }
  54. }
  55. } else
  56. #endif
  57. {
  58. #if __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
  59. return [UIApplication sharedApplication].keyWindow;
  60. #endif
  61. }
  62. return keyWindow;
  63. }
  64. #endif /* BRPickerViewMacro_h */