-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUIView+Positioning.m
More file actions
237 lines (201 loc) · 4.77 KB
/
UIView+Positioning.m
File metadata and controls
237 lines (201 loc) · 4.77 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//
// UIView_Positioning.m
// Mindfulness
//
// Created by Jiva DeVoe on 8/4/09.
// Copyright 2009 Random Ideas, LLC. All rights reserved.
//
#import "UIView+Positioning.h"
@implementation UIView (Positioning)
@dynamic x;
@dynamic y;
@dynamic top;
@dynamic left;
@dynamic right;
@dynamic width;
@dynamic height;
@dynamic bottom;
@dynamic topLeft;
@dynamic topRight;
@dynamic bottomLeft;
@dynamic bottomRight;
@dynamic boundsCenter;
@dynamic topLeftBounds;
@dynamic topRightBounds;
@dynamic bottomLeftBounds;
@dynamic bottomRightBounds;
-(CGPoint)boundsCenter;
{
CGPoint ret = [self bounds].origin;
ret.x += [self bounds].size.width/2;
ret.y += [self bounds].size.height/2;
return ret;
}
- (CGPoint) topLeftBounds
{
CGPoint topLeft = [self bounds].origin;
return topLeft;
}
- (CGPoint) bottomLeftBounds
{
CGPoint bottomLeft = [self bounds].origin;
bottomLeft.y += [self bounds].size.height;
return bottomLeft;
}
- (CGPoint) topRightBounds
{
CGPoint topRight = [self bounds].origin;
topRight.x += [self bounds].size.width;
return topRight;
}
- (CGPoint) bottomRightBounds
{
CGPoint bottomRight = [self bounds].origin;
bottomRight.x += [self bounds].size.width;
bottomRight.y += [self bounds].size.height;
return bottomRight;
}
- (CGPoint) topLeft
{
CGPoint topLeft = [self frame].origin;
return topLeft;
}
- (CGPoint) bottomLeft
{
CGPoint bottomLeft = [self frame].origin;
bottomLeft.y += [self frame].size.height;
return bottomLeft;
}
- (CGPoint) topRight
{
CGPoint topRight = [self frame].origin;
topRight.x += [self frame].size.width;
return topRight;
}
- (CGPoint) bottomRight
{
CGPoint bottomRight = [self frame].origin;
bottomRight.x += [self frame].size.width;
bottomRight.y += [self frame].size.height;
return bottomRight;
}
//+(void)beginRemoveViewAnimationForView:(UIView *)inView
//{
//[self beginAnimations:@"REMOVINGSUBVIEW" context:inView];
//[self setAnimationDelegate:self];
//[self setAnimationDidStopSelector:@selector(removalAnimationFinished:finished:userInfo:)];
//}
//
//+(void)removalAnimationFinished:(NSString *)inAnimationId finished:(BOOL)inFinished userInfo:(void *)inContext;
//{
//UIView *view = (UIView *)inContext;
//[view removeFromSuperview];
//}
-(void)evenlyDistributeHorizontallySubviewsInArray:(NSArray *)inSubviews;
{
CGFloat myWidth = self.bounds.size.width;
CGFloat itemWidth = myWidth/[inSubviews count];
for(NSInteger n = 0; n < [inSubviews count]; ++n)
{
id subview = [inSubviews objectAtIndex:n];
if([subview isKindOfClass:[UIView class]])
{
CGFloat location = (itemWidth * n)+(itemWidth/2);
[subview setX:location];
}
}
}
-(void)spreadSubviewsIntoGrid:(NSArray *)inGridOfSubviews; // columns:(NSInteger)inColumns; // rows:(NSInteger)rows;
{
NSUInteger rows = [inGridOfSubviews count];
CGFloat myHeight = self.bounds.size.height;
CGFloat itemHeight = myHeight/rows;
for(NSUInteger n = 0; n < [inGridOfSubviews count]; ++n)
{
NSArray *row = [inGridOfSubviews objectAtIndex:n];
CGFloat location = (itemHeight * n)+(itemHeight/2);
for(id subview in row)
{
if([subview isKindOfClass:[UIView class]])
[subview setY:location];
}
[self evenlyDistributeHorizontallySubviewsInArray:row];
}
}
-(CGFloat)y;
{
return self.center.y;
}
-(CGFloat)x;
{
return self.center.x;
}
-(void)setY:(CGFloat)inY;
{
[self setCenter:CGPointMake(self.center.x, inY)];
}
-(void)setX:(CGFloat)inX;
{
[self setCenter:CGPointMake(inX, self.center.y)];
}
-(CGFloat)top;
{
return self.frame.origin.y;
}
-(CGFloat)left;
{
return self.frame.origin.x;
}
-(void)setTop:(CGFloat)inY;
{
CGRect frame = [self frame];
frame.origin.y = inY;
[self setFrame:frame];
}
-(void)setLeft:(CGFloat)inX;
{
CGRect frame = [self frame];
frame.origin.x = inX;
[self setFrame:frame];
}
-(CGFloat)right;
{
return self.left + self.width;
}
-(void)setRight:(CGFloat)inRight;
{
self.left = inRight - self.width;
}
-(CGFloat)width;
{
return self.frame.size.width;
}
-(CGFloat)height;
{
return self.frame.size.height;
}
-(CGFloat)bottom
{
return self.top + self.height;
}
-(void)setBottom:(CGFloat)inBottom;
{
self.top = inBottom - self.height;
}
-(void)setWidth:(CGFloat)inWidth;
{
CGRect frame = [self frame];
frame.size.width = inWidth;
[self setFrame:frame];
}
-(void)setHeight:(CGFloat)inHeight;
{
CGRect frame = [self frame];
frame.size.height = inHeight;
[self setFrame:frame];
}
-(CGRect)frameInRelationToView:(UIView *)inView;
{
return [self convertRect:[self frame] toView:inView];
}
@end