View+MASAdditions.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_MAX_ALLOWED >= 110000) || (__TV_OS_VERSION_MAX_ALLOWED >= 110000)
  46. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide API_AVAILABLE(ios(11.0),tvos(11.0));
  47. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0),tvos(11.0));
  48. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0),tvos(11.0));
  49. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0),tvos(11.0));
  50. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0),tvos(11.0));
  51. #endif
  52. /**
  53. * a key to associate with this view
  54. */
  55. @property (nonatomic, strong) id mas_key;
  56. /**
  57. * Finds the closest common superview between this view and another view
  58. *
  59. * @param view other view
  60. *
  61. * @return returns nil if common superview could not be found
  62. */
  63. - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
  64. /**
  65. * Creates a MASConstraintMaker with the callee view.
  66. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing
  67. *
  68. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  69. *
  70. * @return Array of created MASConstraints
  71. */
  72. - (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  73. /**
  74. * Creates a MASConstraintMaker with the callee view.
  75. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
  76. * If an existing constraint exists then it will be updated instead.
  77. *
  78. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  79. *
  80. * @return Array of created/updated MASConstraints
  81. */
  82. - (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  83. /**
  84. * Creates a MASConstraintMaker with the callee view.
  85. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
  86. * All constraints previously installed for the view will be removed.
  87. *
  88. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  89. *
  90. * @return Array of created/updated MASConstraints
  91. */
  92. - (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  93. @end