View+MASShorthandAdditions.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 TARGET_OS_IPHONE
  28. @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin;
  29. @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin;
  30. @property (nonatomic, strong, readonly) MASViewAttribute *topMargin;
  31. @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin;
  32. @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin;
  33. @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin;
  34. @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins;
  35. @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins;
  36. #endif
  37. - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
  38. - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
  39. - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
  40. @end
  41. #define MAS_ATTR_FORWARD(attr) \
  42. - (MASViewAttribute *)attr { \
  43. return [self mas_##attr]; \
  44. }
  45. @implementation MAS_VIEW (MASShorthandAdditions)
  46. MAS_ATTR_FORWARD(top);
  47. MAS_ATTR_FORWARD(left);
  48. MAS_ATTR_FORWARD(bottom);
  49. MAS_ATTR_FORWARD(right);
  50. MAS_ATTR_FORWARD(leading);
  51. MAS_ATTR_FORWARD(trailing);
  52. MAS_ATTR_FORWARD(width);
  53. MAS_ATTR_FORWARD(height);
  54. MAS_ATTR_FORWARD(centerX);
  55. MAS_ATTR_FORWARD(centerY);
  56. MAS_ATTR_FORWARD(baseline);
  57. #if TARGET_OS_IPHONE
  58. MAS_ATTR_FORWARD(leftMargin);
  59. MAS_ATTR_FORWARD(rightMargin);
  60. MAS_ATTR_FORWARD(topMargin);
  61. MAS_ATTR_FORWARD(bottomMargin);
  62. MAS_ATTR_FORWARD(leadingMargin);
  63. MAS_ATTR_FORWARD(trailingMargin);
  64. MAS_ATTR_FORWARD(centerXWithinMargins);
  65. MAS_ATTR_FORWARD(centerYWithinMargins);
  66. #endif
  67. - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
  68. return [self mas_attribute];
  69. }
  70. - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
  71. return [self mas_makeConstraints:block];
  72. }
  73. - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
  74. return [self mas_updateConstraints:block];
  75. }
  76. - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
  77. return [self mas_remakeConstraints:block];
  78. }
  79. @end
  80. #endif