View+MASShorthandAdditions.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline;
  28. @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline;
  29. #if TARGET_OS_IPHONE || TARGET_OS_TV
  30. @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin;
  31. @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin;
  32. @property (nonatomic, strong, readonly) MASViewAttribute *topMargin;
  33. @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin;
  34. @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin;
  35. @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin;
  36. @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins;
  37. @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins;
  38. #endif
  39. #if TARGET_OS_IPHONE || TARGET_OS_TV
  40. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
  41. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
  42. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
  43. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
  44. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
  45. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
  46. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
  47. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
  48. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
  49. @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);
  50. #endif
  51. - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
  52. - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
  53. - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
  54. @end
  55. #define MAS_ATTR_FORWARD(attr) \
  56. - (MASViewAttribute *)attr { \
  57. return [self mas_##attr]; \
  58. }
  59. #define MAS_ATTR_FORWARD_AVAILABLE(attr, available) \
  60. - (MASViewAttribute *)attr available { \
  61. return [self mas_##attr]; \
  62. }
  63. @implementation MAS_VIEW (MASShorthandAdditions)
  64. MAS_ATTR_FORWARD(top);
  65. MAS_ATTR_FORWARD(left);
  66. MAS_ATTR_FORWARD(bottom);
  67. MAS_ATTR_FORWARD(right);
  68. MAS_ATTR_FORWARD(leading);
  69. MAS_ATTR_FORWARD(trailing);
  70. MAS_ATTR_FORWARD(width);
  71. MAS_ATTR_FORWARD(height);
  72. MAS_ATTR_FORWARD(centerX);
  73. MAS_ATTR_FORWARD(centerY);
  74. MAS_ATTR_FORWARD(baseline);
  75. MAS_ATTR_FORWARD(firstBaseline);
  76. MAS_ATTR_FORWARD(lastBaseline);
  77. #if TARGET_OS_IPHONE || TARGET_OS_TV
  78. MAS_ATTR_FORWARD(leftMargin);
  79. MAS_ATTR_FORWARD(rightMargin);
  80. MAS_ATTR_FORWARD(topMargin);
  81. MAS_ATTR_FORWARD(bottomMargin);
  82. MAS_ATTR_FORWARD(leadingMargin);
  83. MAS_ATTR_FORWARD(trailingMargin);
  84. MAS_ATTR_FORWARD(centerXWithinMargins);
  85. MAS_ATTR_FORWARD(centerYWithinMargins);
  86. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeading, NS_AVAILABLE_IOS(11.0));
  87. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTrailing, NS_AVAILABLE_IOS(11.0));
  88. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeft, NS_AVAILABLE_IOS(11.0));
  89. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideRight, NS_AVAILABLE_IOS(11.0));
  90. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTop, NS_AVAILABLE_IOS(11.0));
  91. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideBottom, NS_AVAILABLE_IOS(11.0));
  92. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideWidth, NS_AVAILABLE_IOS(11.0));
  93. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, NS_AVAILABLE_IOS(11.0));
  94. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, NS_AVAILABLE_IOS(11.0));
  95. MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, NS_AVAILABLE_IOS(11.0));
  96. #endif
  97. - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
  98. return [self mas_attribute];
  99. }
  100. - (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
  101. return [self mas_makeConstraints:block];
  102. }
  103. - (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
  104. return [self mas_updateConstraints:block];
  105. }
  106. - (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
  107. return [self mas_remakeConstraints:block];
  108. }
  109. @end
  110. #endif