View+MASShorthandAdditions.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // UIView+MASShorthandAdditions.h
  3. // Masonry
  4. //
  5. // Created by Jonas Budelmann on 22/07/13.
  6. // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7. //
  8. #import "View+MASAdditions.h"
  9. #ifdef MAS_SHORTHAND
  10. /**
  11. * Shorthand view additions without the 'mas_' prefixes,
  12. * only enabled if MAS_SHORTHAND is defined
  13. */
  14. @interface MAS_VIEW (MASShorthandAdditions)
  15. @property (nonatomic, strong, readonly) MASViewAttribute *left;
  16. @property (nonatomic, strong, readonly) MASViewAttribute *top;
  17. @property (nonatomic, strong, readonly) MASViewAttribute *right;
  18. @property (nonatomic, strong, readonly) MASViewAttribute *bottom;
  19. @property (nonatomic, strong, readonly) MASViewAttribute *leading;
  20. @property (nonatomic, strong, readonly) MASViewAttribute *trailing;
  21. @property (nonatomic, strong, readonly) MASViewAttribute *width;
  22. @property (nonatomic, strong, readonly) MASViewAttribute *height;
  23. @property (nonatomic, strong, readonly) MASViewAttribute *centerX;
  24. @property (nonatomic, strong, readonly) MASViewAttribute *centerY;
  25. @property (nonatomic, strong, readonly) MASViewAttribute *baseline;
  26. @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);
  27. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
  28. @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline;
  29. @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline;
  30. #endif
  31. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
  32. @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin;
  33. @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin;
  34. @property (nonatomic, strong, readonly) MASViewAttribute *topMargin;
  35. @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin;
  36. @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin;
  37. @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin;
  38. @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins;
  39. @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins;
  40. #endif
  41. #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 110000) || (__TV_OS_VERSION_MAX_ALLOWED >= 110000)
  42. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0),tvos(11.0));
  43. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0),tvos(11.0));
  44. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0),tvos(11.0));
  45. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0),tvos(11.0));
  46. #endif
  47. - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
  48. - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
  49. - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
  50. @end
  51. #define MAS_ATTR_FORWARD(attr) \
  52. - (MASViewAttribute *)attr { \
  53. return [self mas_##attr]; \
  54. }
  55. @implementation MAS_VIEW (MASShorthandAdditions)
  56. MAS_ATTR_FORWARD(top);
  57. MAS_ATTR_FORWARD(left);
  58. MAS_ATTR_FORWARD(bottom);
  59. MAS_ATTR_FORWARD(right);
  60. MAS_ATTR_FORWARD(leading);
  61. MAS_ATTR_FORWARD(trailing);
  62. MAS_ATTR_FORWARD(width);
  63. MAS_ATTR_FORWARD(height);
  64. MAS_ATTR_FORWARD(centerX);
  65. MAS_ATTR_FORWARD(centerY);
  66. MAS_ATTR_FORWARD(baseline);
  67. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
  68. MAS_ATTR_FORWARD(firstBaseline);
  69. MAS_ATTR_FORWARD(lastBaseline);
  70. #endif
  71. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
  72. MAS_ATTR_FORWARD(leftMargin);
  73. MAS_ATTR_FORWARD(rightMargin);
  74. MAS_ATTR_FORWARD(topMargin);
  75. MAS_ATTR_FORWARD(bottomMargin);
  76. MAS_ATTR_FORWARD(leadingMargin);
  77. MAS_ATTR_FORWARD(trailingMargin);
  78. MAS_ATTR_FORWARD(centerXWithinMargins);
  79. MAS_ATTR_FORWARD(centerYWithinMargins);
  80. #endif
  81. #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 110000) || (__TV_OS_VERSION_MAX_ALLOWED >= 110000)
  82. MAS_ATTR_FORWARD(safeAreaLayoutGuideTop);
  83. MAS_ATTR_FORWARD(safeAreaLayoutGuideBottom);
  84. MAS_ATTR_FORWARD(safeAreaLayoutGuideLeft);
  85. MAS_ATTR_FORWARD(safeAreaLayoutGuideRight);
  86. #endif
  87. - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
  88. return [self mas_attribute];
  89. }
  90. - (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
  91. return [self mas_makeConstraints:block];
  92. }
  93. - (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
  94. return [self mas_updateConstraints:block];
  95. }
  96. - (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
  97. return [self mas_remakeConstraints:block];
  98. }
  99. @end
  100. #endif