-
Notifications
You must be signed in to change notification settings - Fork 3
/
UIView+Constraints.m
72 lines (58 loc) · 2.22 KB
/
UIView+Constraints.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
#include "UIView+Constraints.h"
@implementation UIView (fconstraints)
- (void)atlas_anchorTop:(NSLayoutAnchor<NSLayoutYAxisAnchor *> *)top
leading:(NSLayoutAnchor<NSLayoutXAxisAnchor *> *)leading
bottom:(NSLayoutAnchor<NSLayoutYAxisAnchor *> *)bottom
trailing:(NSLayoutAnchor<NSLayoutXAxisAnchor *> *)trailing
padding:(UIEdgeInsets)insets
size:(CGSize)size {
self.translatesAutoresizingMaskIntoConstraints = NO;
if (top != nil) {
[self.topAnchor constraintEqualToAnchor:top constant:insets.top].active =
YES;
}
if (leading != nil) {
[self.leadingAnchor constraintEqualToAnchor:leading constant:insets.left]
.active = YES;
}
if (bottom != nil) {
[self.bottomAnchor constraintEqualToAnchor:bottom constant:-insets.bottom]
.active = YES;
}
if (trailing != nil) {
[self.trailingAnchor constraintEqualToAnchor:trailing
constant:-insets.right]
.active = YES;
}
if (size.width != 0) {
[self.widthAnchor constraintEqualToConstant:size.width].active = YES;
}
if (size.height != 0) {
[self.heightAnchor constraintEqualToConstant:size.height].active = YES;
}
}
- (void)atlas_anchorSizeToView:(UIView *)view {
[self.widthAnchor constraintEqualToAnchor:view.widthAnchor].active = YES;
[self.heightAnchor constraintEqualToAnchor:view.heightAnchor].active = YES;
}
- (void)atlas_centerInView:(UIView *)view {
[self.centerYAnchor constraintEqualToAnchor:view.centerYAnchor].active = YES;
[self.centerXAnchor constraintEqualToAnchor:view.centerXAnchor].active = YES;
}
- (void)atlas_heightWidthAnchorsEqualToSize:(CGSize)size {
if (size.width != 0) {
[self.widthAnchor constraintEqualToConstant:size.width].active = YES;
}
if (size.height != 0) {
[self.heightAnchor constraintEqualToConstant:size.height].active = YES;
}
}
- (void)atlas_fillSuperview {
[self atlas_anchorTop:self.superview.topAnchor
leading:self.superview.leadingAnchor
bottom:self.superview.bottomAnchor
trailing:self.superview.trailingAnchor
padding:UIEdgeInsetsZero
size:CGSizeZero];
}
@end