View+MASAdditions.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // UIView+MASAdditions.h
  3. // Masonry
  4. //
  5. // Created by Jonas Budelmann on 20/07/13.
  6. // Copyright (c) 2013 cloudling. All rights reserved.
  7. //
  8. #import "MASUtilities.h"
  9. #import "MASConstraintMaker.h"
  10. #import "MASViewAttribute.h"
  11. /**
  12. * Provides constraint maker block
  13. * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs
  14. */
  15. @interface MAS_VIEW (MASAdditions)
  16. /**
  17. * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute
  18. */
  19. @property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
  20. @property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
  21. @property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
  22. @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
  23. @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
  24. @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
  25. @property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
  26. @property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
  27. @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
  28. @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
  29. @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
  30. @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr);
  31. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
  32. @property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline;
  33. @property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline;
  34. #endif
  35. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
  36. @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin;
  37. @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin;
  38. @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin;
  39. @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin;
  40. @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin;
  41. @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin;
  42. @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins;
  43. @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins;
  44. #endif
  45. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (__TV_OS_VERSION_MIN_REQUIRED >= 110000)
  46. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide;
  47. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeading;
  48. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTrailing;
  49. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft;
  50. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight;
  51. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop;
  52. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom;
  53. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideWidth;
  54. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideHeight;
  55. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX;
  56. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY;
  57. #endif
  58. /**
  59. * a key to associate with this view
  60. */
  61. @property (nonatomic, strong) id mas_key;
  62. /**
  63. * Finds the closest common superview between this view and another view
  64. *
  65. * @param view other view
  66. *
  67. * @return returns nil if common superview could not be found
  68. */
  69. - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
  70. /**
  71. * Creates a MASConstraintMaker with the callee view.
  72. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing
  73. *
  74. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  75. *
  76. * @return Array of created MASConstraints
  77. */
  78. - (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  79. /**
  80. * Creates a MASConstraintMaker with the callee view.
  81. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
  82. * If an existing constraint exists then it will be updated instead.
  83. *
  84. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  85. *
  86. * @return Array of created/updated MASConstraints
  87. */
  88. - (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  89. /**
  90. * Creates a MASConstraintMaker with the callee view.
  91. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
  92. * All constraints previously installed for the view will be removed.
  93. *
  94. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  95. *
  96. * @return Array of created/updated MASConstraints
  97. */
  98. - (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  99. @end