UIView+BUAdditions.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // UIView+Additions.h
  3. // BUAdSDK
  4. //
  5. // Created by bytedance_yuanhuan on 2018/3/15.
  6. // Copyright © 2018年 bytedance. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. @interface UIView (BU_Additions)
  11. - (UIImage *)bu_captureView;
  12. @end
  13. typedef enum {
  14. UIViewBorderOptionTop = 0,
  15. UIViewBorderOptionRight,
  16. UIViewBorderOptionBottom,
  17. UIViewBorderOptionLeft,
  18. UIViewBorderOptionAll
  19. } UIViewBorderOption;
  20. typedef struct {
  21. CGFloat topLeft;
  22. CGFloat topRight;
  23. CGFloat bottomLeft;
  24. CGFloat bottomRight;
  25. } BUFCornerRadii;
  26. @interface UIView (BU_Border)
  27. - (void)bu_setBorder:(UIViewBorderOption)option width:(CGFloat)width color:(UIColor *)color;
  28. - (void)bu_setDashBorder:(UIViewBorderOption)option width:(CGFloat)width color:(UIColor *)color;
  29. - (void)bu_roundCornerWithDashBorder:(CGFloat)radius width:(CGFloat)widht color:(UIColor *)color;
  30. - (void)bu_updateClippingForLayer:(CALayer *)layer cornerRadii:(BUFCornerRadii)cornerRadii maxRadius:(CGFloat)maxRadius;
  31. @end
  32. @interface UIView (BU_FrameAdditions)
  33. @property (nonatomic) float bu_x;
  34. @property (nonatomic) float bu_y;
  35. @property (nonatomic) float bu_width;
  36. @property (nonatomic) float bu_height;
  37. @property (nonatomic, getter = bu_y,setter = setBu_y:) float bu_top; // 增加bu前缀,防止与外部开发者的分类属性名冲突:https://jira.bytedance.com/browse/UNION-4447 fixed in 3300 by chaors
  38. @property (nonatomic, getter = bu_x,setter = setBu_x:) float bu_left;
  39. @property (nonatomic) float bu_bottom;
  40. @property (nonatomic) float bu_right;
  41. @property (nonatomic) CGSize bu_size;
  42. @property (nonatomic) CGPoint bu_origin;
  43. @property (nonatomic) CGFloat bu_centerX;
  44. @property (nonatomic) CGFloat bu_centerY;
  45. // 设置最大右边
  46. - (void)bu_setMaxRight:(CGFloat)maxRight;
  47. - (UIViewController *)bu_viewController;
  48. @end
  49. @interface UIView (BU_TKCategory)
  50. // DRAW GRADIENT
  51. + (void)bu_drawGradientInRect:(CGRect)rect withColors:(NSArray*)colors;
  52. // DRAW ROUNDED RECTANGLE
  53. + (void)bu_drawRoundRectangleInRect:(CGRect)rect withRadius:(CGFloat)radius color:(UIColor*)color;
  54. // DRAW LINE
  55. + (void)bu_drawLineInRect:(CGRect)rect red:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
  56. + (void)bu_drawLineInRect:(CGRect)rect colors:(CGFloat[_Nullable])colors;
  57. + (void)bu_drawLineInRect:(CGRect)rect colors:(CGFloat[_Nullable])colors width:(CGFloat)lineWidth cap:(CGLineCap)cap;
  58. @end
  59. @interface UIView (BU_Gesture)
  60. - (UILongPressGestureRecognizer *)bu_addLogPressGestureWithTarget:(id)target selecter:(SEL)aSelector;
  61. @property (nonatomic, strong, nullable) UITapGestureRecognizer *bu_tgr;
  62. // 会移除旧的手势
  63. - (void)bu_addGestureRecognizerWithTarget:(id)target action:(SEL)action;
  64. - (void)bu_removeGestureRecognizer;
  65. @end
  66. @interface UIView (BU_FindFirstResponder)
  67. - (UIView *)bu_findViewThatIsFirstResponder;
  68. @end
  69. @interface UIView (BU_InScreen)
  70. - (BOOL)bu_checkInCurrentScreenWithEdgeInsets:(UIEdgeInsets)edgeInsets;
  71. - (BOOL)bu_checkInScreenYWithPaddingTop:(CGFloat)paddingTop paddingToBottom:(CGFloat)paddingToBottom;
  72. - (BOOL)bu_checkInScreenXWithPaddingLeft:(CGFloat)paddingLeft paddingToRight:(CGFloat)paddingToRight;
  73. @end
  74. @interface UIView (BU_NearestController)
  75. - (UIViewController *)bu_findNearestController;
  76. @end
  77. @interface UIView (BU_SafeArea)
  78. - (UIEdgeInsets)bu_safeAreaInsets;
  79. + (UIEdgeInsets)bu_defaultAreaInsets;
  80. @end
  81. NS_ASSUME_NONNULL_END