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