Last active
December 19, 2015 18:19
-
-
Save palimondo/5998280 to your computer and use it in GitHub Desktop.
Concise Auto Layout macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define Left NSLayoutAttributeLeft | |
#define Right NSLayoutAttributeRight | |
#define Top NSLayoutAttributeTop | |
#define Bottom NSLayoutAttributeBottom | |
#define Leading NSLayoutAttributeLeading | |
#define Trailing NSLayoutAttributeTrailing | |
#define Width NSLayoutAttributeWidth | |
#define Height NSLayoutAttributeHeight | |
#define CenterX NSLayoutAttributeCenterX | |
#define CenterY NSLayoutAttributeCenterY | |
#define Baseline NSLayoutAttributeBaseline | |
#define LessThanOrEqual NSLayoutRelationLessThanOrEqual | |
#define Equal NSLayoutRelationEqual | |
#define GreaterThanOrEqual NSLayoutRelationGreaterThanOrEqual | |
#define Constraint(item1, attr1, rel, item2, attr2, con) [NSLayoutConstraint constraintWithItem:(item1) attribute:(attr1) relatedBy:(rel) toItem:(item2) attribute:(attr2) multiplier:1 constant:(con)] | |
#define VisualConstraints(format, ...) [NSLayoutConstraint constraintsWithVisualFormat:(format) options:0 metrics:nil views:_NSDictionaryOfVariableBindings(@"" # __VA_ARGS__, __VA_ARGS__, nil)] | |
#define VisualConstraintWithMetrics(format, theMetrics, ...) [NSLayoutConstraint constraintsWithVisualFormat:(format) options:0 metrics:(theMetrics) views:_NSDictionaryOfVariableBindings(@"" # __VA_ARGS__, __VA_ARGS__, nil)] | |
#define ConstantConstraint(item, attr, rel, con) Constraint((item), (attr), (rel), nil, NSLayoutAttributeNotAnAttribute, (con)) | |
#define horizontallyFillSuperview ^(UIView *view, NSUInteger idx, BOOL *stop) {[view.superview addConstraints:VisualConstraints(@"|[view]|", view)];} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment