UIView+RQExtension.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // UIView+RQExtension.h
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/16.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. typedef void (^GestureActionBlock)(UIGestureRecognizer *gestureRecoginzer);
  10. @interface UIView (RQExtension)
  11. typedef NS_ENUM(NSInteger, GradientStyle) {
  12. GradientStyleLeftToRight = 1,//渐变左到右
  13. GradientStyleTopToBottom = 2//渐变上到下
  14. };
  15. /**
  16. * 判断一个控件是否真正显示在主窗口
  17. */
  18. - (BOOL)rq_isShowingOnKeyWindow;
  19. /**
  20. * xib创建的view
  21. */
  22. + (instancetype)rq_viewFromXib;
  23. /**
  24. * xib创建的view
  25. */
  26. + (instancetype)rq_viewFromXibWithFrame:(CGRect)frame;
  27. /**
  28. * xib中显示的属性
  29. */
  30. ///头部圆角
  31. @property (nonatomic, assign) IBInspectable BOOL roundTop;
  32. ///底部圆角
  33. @property (nonatomic, assign) IBInspectable BOOL roundBottom;
  34. ///左边圆角
  35. @property (nonatomic, assign) IBInspectable BOOL roundLeft;
  36. ///右边圆角
  37. @property (nonatomic, assign) IBInspectable BOOL roundRight;
  38. ///圆
  39. @property (nonatomic, assign) IBInspectable BOOL circle;
  40. ///圆角
  41. @property (nonatomic, assign) IBInspectable CGFloat cornerRadius;
  42. ///边框宽度
  43. @property (nonatomic, assign) IBInspectable CGFloat borderWidth;
  44. ///边框颜色
  45. @property (nonatomic, strong) IBInspectable UIColor *borderColor;
  46. ///阴影颜色
  47. @property (nonatomic, strong) IBInspectable UIColor *shadowColor;
  48. ///阴影半径 默认1
  49. @property (nonatomic, assign) IBInspectable CGFloat shadowRadius;
  50. ///阴影透明度 默认1
  51. @property (nonatomic, assign) IBInspectable CGFloat shadowOpacity;
  52. ///阴影偏移
  53. @property (nonatomic, assign) IBInspectable CGSize shadowOffset;
  54. ///是否开启主题渐变风格 (很多APP渐变风格大多数都是一致了.为了更快设置颜色而添加的属性,具体用法实现UIView+Theme方法)
  55. @property (nonatomic, assign) IBInspectable BOOL themeGradientEnable;
  56. ///渐变方向
  57. @property(nonatomic, assign) GradientStyle gradientStyle;
  58. ///渐变方向 xib用
  59. @property(nonatomic, assign) IBInspectable NSInteger gradientStyleEnum;
  60. ///渐变A颜色
  61. @property (nonatomic, strong) IBInspectable UIColor *gradientAColor;
  62. ///渐变B颜色
  63. @property (nonatomic, strong) IBInspectable UIColor *gradientBColor;
  64. /// 阴影Layer
  65. @property(nonatomic, strong) UIView *shadowView;
  66. // 渐变Layer
  67. @property(nonatomic, strong) CAGradientLayer *gradientLayer;
  68. // 边圆角Layer
  69. @property(nonatomic, strong) CAShapeLayer *maskLayer;
  70. ///上一次大小
  71. @property (nonatomic, copy) NSString *lastSize;
  72. /// < Shortcut for frame.origin.x.
  73. @property (nonatomic, readwrite, assign) CGFloat rq_left;
  74. /// < Shortcut for frame.origin.y
  75. @property (nonatomic, readwrite, assign) CGFloat rq_top;
  76. /// < Shortcut for frame.origin.x + frame.size.width
  77. @property (nonatomic, readwrite, assign) CGFloat rq_right;
  78. /// < Shortcut for frame.origin.y + frame.size.height
  79. @property (nonatomic, readwrite, assign) CGFloat rq_bottom;
  80. /// < Shortcut for frame.origin.x.
  81. @property (nonatomic, readwrite, assign) CGFloat rq_x;
  82. /// < Shortcut for frame.origin.y
  83. @property (nonatomic, readwrite, assign) CGFloat rq_y;
  84. /// < Shortcut for frame.size.width
  85. @property (nonatomic, readwrite, assign) CGFloat rq_width;
  86. /// < Shortcut for frame.size.height
  87. @property (nonatomic, readwrite, assign) CGFloat rq_height;
  88. /// < Shortcut for center.x
  89. @property (nonatomic, readwrite, assign) CGFloat rq_centerX;
  90. ///< Shortcut for center.y
  91. @property (nonatomic, readwrite, assign) CGFloat rq_centerY;
  92. /// < Shortcut for frame.size.
  93. @property (nonatomic, readwrite, assign) CGSize rq_size;
  94. /// < Shortcut for frame.origin.
  95. @property (nonatomic, readwrite, assign) CGPoint rq_origin;
  96. /**
  97. * @brief 添加tap手势
  98. * @param block 代码块
  99. */
  100. - (void)addTapActionWithBlock:(GestureActionBlock)block;
  101. /**
  102. * @brief 添加长按手势
  103. * @param block 代码块
  104. */
  105. - (void)addLongPressActionWithBlock:(GestureActionBlock)block;
  106. @end