123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //
- // UIView+MASShorthandAdditions.h
- // Masonry
- //
- // Created by Jonas Budelmann on 22/07/13.
- // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
- //
- #import "View+MASAdditions.h"
- #ifdef MAS_SHORTHAND
- /**
- * Shorthand view additions without the 'mas_' prefixes,
- * only enabled if MAS_SHORTHAND is defined
- */
- @interface MAS_VIEW (MASShorthandAdditions)
- @property (nonatomic, strong, readonly) MASViewAttribute *left;
- @property (nonatomic, strong, readonly) MASViewAttribute *top;
- @property (nonatomic, strong, readonly) MASViewAttribute *right;
- @property (nonatomic, strong, readonly) MASViewAttribute *bottom;
- @property (nonatomic, strong, readonly) MASViewAttribute *leading;
- @property (nonatomic, strong, readonly) MASViewAttribute *trailing;
- @property (nonatomic, strong, readonly) MASViewAttribute *width;
- @property (nonatomic, strong, readonly) MASViewAttribute *height;
- @property (nonatomic, strong, readonly) MASViewAttribute *centerX;
- @property (nonatomic, strong, readonly) MASViewAttribute *centerY;
- @property (nonatomic, strong, readonly) MASViewAttribute *baseline;
- @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);
- #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
- @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline;
- @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline;
- #endif
- #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
- @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin;
- @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin;
- @property (nonatomic, strong, readonly) MASViewAttribute *topMargin;
- @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin;
- @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin;
- @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin;
- @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins;
- @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins;
- #endif
- #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 110000) || (__TV_OS_VERSION_MAX_ALLOWED >= 110000)
- @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0),tvos(11.0));
- @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0),tvos(11.0));
- @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0),tvos(11.0));
- @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0),tvos(11.0));
- #endif
- - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
- - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
- - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
- @end
- #define MAS_ATTR_FORWARD(attr) \
- - (MASViewAttribute *)attr { \
- return [self mas_##attr]; \
- }
- @implementation MAS_VIEW (MASShorthandAdditions)
- MAS_ATTR_FORWARD(top);
- MAS_ATTR_FORWARD(left);
- MAS_ATTR_FORWARD(bottom);
- MAS_ATTR_FORWARD(right);
- MAS_ATTR_FORWARD(leading);
- MAS_ATTR_FORWARD(trailing);
- MAS_ATTR_FORWARD(width);
- MAS_ATTR_FORWARD(height);
- MAS_ATTR_FORWARD(centerX);
- MAS_ATTR_FORWARD(centerY);
- MAS_ATTR_FORWARD(baseline);
- #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
- MAS_ATTR_FORWARD(firstBaseline);
- MAS_ATTR_FORWARD(lastBaseline);
- #endif
- #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
- MAS_ATTR_FORWARD(leftMargin);
- MAS_ATTR_FORWARD(rightMargin);
- MAS_ATTR_FORWARD(topMargin);
- MAS_ATTR_FORWARD(bottomMargin);
- MAS_ATTR_FORWARD(leadingMargin);
- MAS_ATTR_FORWARD(trailingMargin);
- MAS_ATTR_FORWARD(centerXWithinMargins);
- MAS_ATTR_FORWARD(centerYWithinMargins);
- #endif
- #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 110000) || (__TV_OS_VERSION_MAX_ALLOWED >= 110000)
- MAS_ATTR_FORWARD(safeAreaLayoutGuideTop);
- MAS_ATTR_FORWARD(safeAreaLayoutGuideBottom);
- MAS_ATTR_FORWARD(safeAreaLayoutGuideLeft);
- MAS_ATTR_FORWARD(safeAreaLayoutGuideRight);
- #endif
- - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
- return [self mas_attribute];
- }
- - (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
- return [self mas_makeConstraints:block];
- }
- - (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
- return [self mas_updateConstraints:block];
- }
- - (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
- return [self mas_remakeConstraints:block];
- }
- @end
- #endif
|