-
Notifications
You must be signed in to change notification settings - Fork 4
/
UIView+TBL.m
60 lines (48 loc) · 1.86 KB
/
UIView+TBL.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
#import "UIView+TBL.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIView (TBL)
-(void)squareCorners {
self.layer.mask = nil;
}
-(void)roundCorners:(UIRectCorner)corners withRadius:(CGFloat)radius {
if (corners == UIRectCornerAllCorners) {
self.layer.cornerRadius = radius;
} else {
CAShapeLayer *maskLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(radius, radius)];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
maskLayer.path = [roundedPath CGPath];
self.layer.mask = maskLayer;
}
}
-(void)roundCorners:(UIRectCorner)corners {
[self roundCorners:corners withRadius:8];
}
-(void)setX:(CGFloat)newX {
CGRect frame = self.frame;
self.frame = CGRectMake(newX, frame.origin.y, frame.size.width, frame.size.height);
}
-(void)setY:(CGFloat)newY {
CGRect frame = self.frame;
self.frame = CGRectMake(frame.origin.x, newY, frame.size.width, frame.size.height);
}
-(void)setOrigin:(CGPoint)newOrigin {
CGRect frame = self.frame;
self.frame = CGRectMake(newOrigin.x, newOrigin.y, frame.size.width, frame.size.height);
}
-(void)setWidth:(CGFloat)newWidth {
CGRect frame = self.frame;
self.frame = CGRectMake(frame.origin.x, frame.origin.y, newWidth, frame.size.height);
}
-(void)setHeight:(CGFloat)newHeight {
CGRect frame = self.frame;
self.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, newHeight);
}
-(void)setSize:(CGSize)newSize {
CGRect frame = self.frame;
self.frame = CGRectMake(frame.origin.x, frame.origin.y, newSize.width, newSize.height);
}
@end