-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIView+BDKGeometry.m
151 lines (115 loc) · 4 KB
/
UIView+BDKGeometry.m
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#import "UIView+BDKGeometry.h"
#import "BDKGeometry.h"
@implementation UIView (BDKGeometry)
@dynamic frameOrigin, frameXOrigin, frameYOrigin, frameSize, frameWidth, frameHeight;
@dynamic boundsOrigin, boundsXOrigin, boundsYOrigin, boundsSize, boundsWidth, boundsHeight;
#pragma mark - Frame methods
- (void)setFrameOrigin:(CGPoint)frameOrigin {
self.frame = CGRectSetOrigin(self.frame, frameOrigin);
}
- (CGPoint)frameOrigin {
return self.frame.origin;
}
- (void)setFrameXOrigin:(CGFloat)frameXOrigin {
self.frame = CGRectSetXOrigin(self.frame, frameXOrigin);
}
- (CGFloat)frameXOrigin {
return self.frame.origin.x;
}
- (void)setFrameYOrigin:(CGFloat)frameYOrigin {
self.frame = CGRectSetYOrigin(self.frame, frameYOrigin);
}
- (CGFloat)frameYOrigin {
return self.frame.origin.y;
}
- (void)setFrameSize:(CGSize)frameSize {
self.frame = CGRectSetSize(self.frame, frameSize);
}
- (CGSize)frameSize {
return self.frame.size;
}
- (void)setFrameWidth:(CGFloat)frameWidth {
self.frame = CGRectSetWidth(self.frame, frameWidth);
}
- (CGFloat)frameWidth {
return self.frame.size.width;
}
- (void)setFrameHeight:(CGFloat)frameHeight {
self.frame = CGRectSetHeight(self.frame, frameHeight);
}
- (CGFloat)frameHeight {
return self.frame.size.height;
}
#pragma mark - Bounds methods
- (void)setBoundsOrigin:(CGPoint)boundsOrigin {
self.bounds = CGRectSetOrigin(self.bounds, boundsOrigin);
}
- (CGPoint)boundsOrigin {
return self.bounds.origin;
}
- (void)setBoundsXOrigin:(CGFloat)boundsXOrigin {
self.bounds = CGRectSetXOrigin(self.bounds, boundsXOrigin);
}
- (CGFloat)boundsXOrigin {
return self.bounds.origin.x;
}
- (void)setBoundsYOrigin:(CGFloat)boundsYOrigin {
self.bounds = CGRectSetYOrigin(self.bounds, boundsYOrigin);
}
- (CGFloat)boundsYOrigin {
return self.bounds.origin.y;
}
- (void)setBoundsSize:(CGSize)boundsSize {
self.bounds = CGRectSetSize(self.bounds, boundsSize);
}
- (CGSize)boundsSize {
return self.bounds.size;
}
- (void)setBoundsWidth:(CGFloat)boundsWidth {
self.bounds = CGRectSetWidth(self.bounds, boundsWidth);
}
- (CGFloat)boundsWidth {
return self.bounds.size.width;
}
- (void)setBoundsHeight:(CGFloat)boundsHeight {
self.bounds = CGRectSetHeight(self.bounds, boundsHeight);
}
- (CGFloat)boundsHeight {
return self.bounds.size.height;
}
- (void)positionViewBelowView:(UIView *)view {
[self positionViewBelowView:view padding:0];
}
- (void)positionViewBelowView:(UIView *)view padding:(CGFloat)padding {
self.frameYOrigin = CGRectGetMaxY(view.frame) + padding;
}
- (void)centerInView:(UIView *)view direction:(BDKGeometryCenter)direction {
switch (direction) {
case BDKGeometryCenterHorizontally:
self.frame = CGRectCenterRectInRectHorizontally(self.frame, view.frame);
break;
case BDKGeometryCenterVertically:
self.frame = CGRectCenterRectInRectVertically(self.frame, view.frame);
break;
case BDKGeometryCenterBoth:
self.frame = CGRectCenterRectInRect(self.frame, view.frame);
break;
default:
break;
}
}
#pragma mark - Autolayout
- (void)constrainSubview:(UIView *)subview withAttribute:(NSLayoutAttribute)attribute constant:(CGFloat)constant {
[self addConstraint:[NSLayoutConstraint constraintWithItem:subview attribute:attribute
relatedBy:NSLayoutRelationEqual
toItem:self attribute:attribute
multiplier:1 constant:0]];;
}
#pragma mark - Deprecated methods
- (void)setOrigin:(CGPoint)origin { self.frameOrigin = origin; }
- (void)setXOrigin:(CGFloat)xOrigin { self.frameXOrigin = xOrigin; }
- (void)setYOrigin:(CGFloat)yOrigin { self.frameYOrigin = yOrigin; }
- (void)setSize:(CGSize)size { self.frameSize = size; }
- (void)setWidth:(CGFloat)width { self.frameWidth = width; }
- (void)setHeight:(CGFloat)height { self.frameHeight = height; }
@end