-
Notifications
You must be signed in to change notification settings - Fork 39
/
UIView+Position.m
105 lines (81 loc) · 2.68 KB
/
UIView+Position.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
//
// UIView+Position.m
//
// Created by Tyler Neylon on 3/19/10.
// Copyright 2010 Bynomial.
//
#import "UIView+position.h"
@implementation UIView (Position)
- (CGPoint)frameOrigin {
return self.frame.origin;
}
- (void)setFrameOrigin:(CGPoint)newOrigin {
self.frame = CGRectMake(newOrigin.x, newOrigin.y, self.frame.size.width, self.frame.size.height);
}
- (CGSize)frameSize {
return self.frame.size;
}
- (void)setFrameSize:(CGSize)newSize {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,
newSize.width, newSize.height);
}
- (CGFloat)frameX {
return self.frame.origin.x;
}
- (void)setFrameX:(CGFloat)newX {
self.frame = CGRectMake(newX, self.frame.origin.y,
self.frame.size.width, self.frame.size.height);
}
- (CGFloat)frameY {
return self.frame.origin.y;
}
- (void)setFrameY:(CGFloat)newY {
self.frame = CGRectMake(self.frame.origin.x, newY,
self.frame.size.width, self.frame.size.height);
}
- (CGFloat)frameRight {
return self.frame.origin.x + self.frame.size.width;
}
- (void)setFrameRight:(CGFloat)newRight {
self.frame = CGRectMake(newRight - self.frame.size.width, self.frame.origin.y,
self.frame.size.width, self.frame.size.height);
}
- (CGFloat)frameBottom {
return self.frame.origin.y + self.frame.size.height;
}
- (void)setFrameBottom:(CGFloat)newBottom {
self.frame = CGRectMake(self.frame.origin.x, newBottom - self.frame.size.height,
self.frame.size.width, self.frame.size.height);
}
- (CGFloat)frameWidth {
return self.frame.size.width;
}
- (void)setFrameWidth:(CGFloat)newWidth {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,
newWidth, self.frame.size.height);
}
- (CGFloat)frameHeight {
return self.frame.size.height;
}
- (void)setFrameHeight:(CGFloat)newHeight {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,
self.frame.size.width, newHeight);
}
- (void)addCenteredSubview:(UIView *)subview {
subview.frameX = (int)((self.bounds.size.width - subview.frameWidth) / 2);
subview.frameY = (int)((self.bounds.size.height - subview.frameHeight) / 2);
[self addSubview:subview];
}
- (void)moveToCenterOfSuperview {
self.frameX = (int)((self.superview.bounds.size.width - self.frameWidth) / 2);
self.frameY = (int)((self.superview.bounds.size.height - self.frameHeight) / 2);
}
- (void)centerVerticallyInSuperview
{
self.frameY = (int)((self.superview.bounds.size.height - self.frameHeight) / 2);
}
- (void)centerHorizontallyInSuperview
{
self.frameX = (int)((self.superview.bounds.size.width - self.frameWidth) / 2);
}
@end