123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- //
- // MASConstraint.h
- // Masonry
- //
- // Created by Jonas Budelmann on 22/07/13.
- // Copyright (c) 2013 cloudling. All rights reserved.
- //
- #import "MASUtilities.h"
- /**
- * Enables Constraints to be created with chainable syntax
- * Constraint can represent single NSLayoutConstraint (MASViewConstraint)
- * or a group of NSLayoutConstraints (MASComposisteConstraint)
- */
- @interface MASConstraint : NSObject
- // Chaining Support
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
- */
- - (MASConstraint * (^)(MASEdgeInsets insets))insets;
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
- */
- - (MASConstraint * (^)(CGFloat inset))inset;
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeWidth, NSLayoutAttributeHeight
- */
- - (MASConstraint * (^)(CGSize offset))sizeOffset;
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
- */
- - (MASConstraint * (^)(CGPoint offset))centerOffset;
- /**
- * Modifies the NSLayoutConstraint constant
- */
- - (MASConstraint * (^)(CGFloat offset))offset;
- /**
- * Modifies the NSLayoutConstraint constant based on a value type
- */
- - (MASConstraint * (^)(NSValue *value))valueOffset;
- /**
- * Sets the NSLayoutConstraint multiplier property
- */
- - (MASConstraint * (^)(CGFloat multiplier))multipliedBy;
- /**
- * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy
- */
- - (MASConstraint * (^)(CGFloat divider))dividedBy;
- /**
- * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
- */
- - (MASConstraint * (^)(MASLayoutPriority priority))priority;
- /**
- * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
- */
- - (MASConstraint * (^)(void))priorityLow;
- /**
- * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
- */
- - (MASConstraint * (^)(void))priorityMedium;
- /**
- * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
- */
- - (MASConstraint * (^)(void))priorityHigh;
- /**
- * Sets the constraint relation to NSLayoutRelationEqual
- * returns a block which accepts one of the following:
- * MASViewAttribute, UIView, NSValue, NSArray
- * see readme for more details.
- */
- - (MASConstraint * (^)(id attr))equalTo;
- /**
- * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
- * returns a block which accepts one of the following:
- * MASViewAttribute, UIView, NSValue, NSArray
- * see readme for more details.
- */
- - (MASConstraint * (^)(id attr))greaterThanOrEqualTo;
- /**
- * Sets the constraint relation to NSLayoutRelationLessThanOrEqual
- * returns a block which accepts one of the following:
- * MASViewAttribute, UIView, NSValue, NSArray
- * see readme for more details.
- */
- - (MASConstraint * (^)(id attr))lessThanOrEqualTo;
- /**
- * Optional semantic property which has no effect but improves the readability of constraint
- */
- - (MASConstraint *)with;
- /**
- * Optional semantic property which has no effect but improves the readability of constraint
- */
- - (MASConstraint *)and;
- /**
- * Creates a new MASCompositeConstraint with the called attribute and reciever
- */
- - (MASConstraint *)left;
- - (MASConstraint *)top;
- - (MASConstraint *)right;
- - (MASConstraint *)bottom;
- - (MASConstraint *)leading;
- - (MASConstraint *)trailing;
- - (MASConstraint *)width;
- - (MASConstraint *)height;
- - (MASConstraint *)centerX;
- - (MASConstraint *)centerY;
- - (MASConstraint *)baseline;
- - (MASConstraint *)firstBaseline;
- - (MASConstraint *)lastBaseline;
- #if TARGET_OS_IPHONE || TARGET_OS_TV
- - (MASConstraint *)leftMargin;
- - (MASConstraint *)rightMargin;
- - (MASConstraint *)topMargin;
- - (MASConstraint *)bottomMargin;
- - (MASConstraint *)leadingMargin;
- - (MASConstraint *)trailingMargin;
- - (MASConstraint *)centerXWithinMargins;
- - (MASConstraint *)centerYWithinMargins;
- #endif
- /**
- * Sets the constraint debug name
- */
- - (MASConstraint * (^)(id key))key;
- // NSLayoutConstraint constant Setters
- // for use outside of mas_updateConstraints/mas_makeConstraints blocks
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
- */
- - (void)setInsets:(MASEdgeInsets)insets;
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
- */
- - (void)setInset:(CGFloat)inset;
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeWidth, NSLayoutAttributeHeight
- */
- - (void)setSizeOffset:(CGSize)sizeOffset;
- /**
- * Modifies the NSLayoutConstraint constant,
- * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
- * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
- */
- - (void)setCenterOffset:(CGPoint)centerOffset;
- /**
- * Modifies the NSLayoutConstraint constant
- */
- - (void)setOffset:(CGFloat)offset;
- // NSLayoutConstraint Installation support
- #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
- /**
- * Whether or not to go through the animator proxy when modifying the constraint
- */
- @property (nonatomic, copy, readonly) MASConstraint *animator;
- #endif
- /**
- * Activates an NSLayoutConstraint if it's supported by an OS.
- * Invokes install otherwise.
- */
- - (void)activate;
- /**
- * Deactivates previously installed/activated NSLayoutConstraint.
- */
- - (void)deactivate;
- /**
- * Creates a NSLayoutConstraint and adds it to the appropriate view.
- */
- - (void)install;
- /**
- * Removes previously installed NSLayoutConstraint
- */
- - (void)uninstall;
- @end
- /**
- * Convenience auto-boxing macros for MASConstraint methods.
- *
- * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax.
- * A potential drawback of this is that the unprefixed macros will appear in global scope.
- */
- #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__)))
- #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
- #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
- #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__)))
- #ifdef MAS_SHORTHAND_GLOBALS
- #define equalTo(...) mas_equalTo(__VA_ARGS__)
- #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__)
- #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__)
- #define offset(...) mas_offset(__VA_ARGS__)
- #endif
- @interface MASConstraint (AutoboxingSupport)
- /**
- * Aliases to corresponding relation methods (for shorthand macros)
- * Also needed to aid autocompletion
- */
- - (MASConstraint * (^)(id attr))mas_equalTo;
- - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo;
- - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo;
- /**
- * A dummy method to aid autocompletion
- */
- - (MASConstraint * (^)(id offset))mas_offset;
- @end
|