MASConstraint.h
4.12 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
//
// MASConstraint.h
// Masonry
//
// Created by Jonas Budelmann on 22/07/13.
// Copyright (c) 2013 cloudling. All rights reserved.
//
#import <UIKit/UIKit.h>
enum {
MASLayoutPriorityRequired = UILayoutPriorityRequired,
MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh,
MASLayoutPriorityDefaultMedium = 500,
MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow,
MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel,
};
typedef float MASLayoutPriority;
/**
* Enables Constraints to be created with chainable syntax
* Constraint can represent single NSLayoutConstraint (MASViewConstraint)
* or a group of NSLayoutConstraints (MASComposisteConstraint)
*/
@protocol MASConstraint <NSObject>
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^insets)(UIEdgeInsets insets);
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeWidth, NSLayoutAttributeHeight
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset);
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset);
/**
* Modifies the NSLayoutConstraint constant
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^offset)(CGFloat offset);
/**
* Sets the NSLayoutConstraint multiplier property
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^percent)(CGFloat percent);
/**
* Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priority)(MASLayoutPriority priority);
/**
* Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityLow)();
/**
* Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityMedium)();
/**
* Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityHigh)();
/**
* Sets the constraint relation to NSLayoutRelationEqual
* returns a block which accepts one of the following:
* MASViewAttribute, UIView, NSNumber, NSArray
* see readme for more details.
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^equalTo)(id attr);
/**
* Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
* returns a block which accepts one of the following:
* MASViewAttribute, UIView, NSNumber, NSArray
* see readme for more details.
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^greaterThanOrEqualTo)(id attr);
/**
* Sets the constraint relation to NSLayoutRelationLessThanOrEqual
* returns a block which accepts one of the following:
* MASViewAttribute, UIView, NSNumber, NSArray
* see readme for more details.
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^lessThanOrEqualTo)(id attr);
/**
* optional semantic property which has no effect but improves the readability of constraint
*/
@property (nonatomic, copy, readonly) id<MASConstraint> with;
/**
* Sets the constraint debug name
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^key)(id key);
/**
* Creates a NSLayoutConstraint. The constraint is added to the first view or the or the closest common superview of the first and second view.
*/
- (void)commit;
@end
@protocol MASConstraintDelegate <NSObject>
/**
* Notifies the delegate when the constraint is has the minimum set of properties.
*
* @param constraint a constraint that has at least a NSLayoutRelation and view
*/
- (void)addConstraint:(id<MASConstraint>)constraint;
@end