View+MASShorthandAdditions.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 TARGET_OS_IPHONE || TARGET_OS_TV
  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. - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
  42. - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
  43. - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
  44. @end
  45. #define MAS_ATTR_FORWARD(attr) \
  46. - (MASViewAttribute *)attr { \
  47. return [self mas_##attr]; \
  48. }
  49. @implementation MAS_VIEW (MASShorthandAdditions)
  50. MAS_ATTR_FORWARD(top);
  51. MAS_ATTR_FORWARD(left);
  52. MAS_ATTR_FORWARD(bottom);
  53. MAS_ATTR_FORWARD(right);
  54. MAS_ATTR_FORWARD(leading);
  55. MAS_ATTR_FORWARD(trailing);
  56. MAS_ATTR_FORWARD(width);
  57. MAS_ATTR_FORWARD(height);
  58. MAS_ATTR_FORWARD(centerX);
  59. MAS_ATTR_FORWARD(centerY);
  60. MAS_ATTR_FORWARD(baseline);
  61. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
  62. MAS_ATTR_FORWARD(firstBaseline);
  63. MAS_ATTR_FORWARD(lastBaseline);
  64. #endif
  65. #if TARGET_OS_IPHONE || TARGET_OS_TV
  66. MAS_ATTR_FORWARD(leftMargin);
  67. MAS_ATTR_FORWARD(rightMargin);
  68. MAS_ATTR_FORWARD(topMargin);
  69. MAS_ATTR_FORWARD(bottomMargin);
  70. MAS_ATTR_FORWARD(leadingMargin);
  71. MAS_ATTR_FORWARD(trailingMargin);
  72. MAS_ATTR_FORWARD(centerXWithinMargins);
  73. MAS_ATTR_FORWARD(centerYWithinMargins);
  74. #endif
  75. - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
  76. return [self mas_attribute];
  77. }
  78. - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
  79. return [self mas_makeConstraints:block];
  80. }
  81. - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
  82. return [self mas_updateConstraints:block];
  83. }
  84. - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
  85. return [self mas_remakeConstraints:block];
  86. }
  87. @end
  88. #endif