View+MASAdditions.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. @property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline;
  32. @property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline;
  33. #if TARGET_OS_IPHONE || TARGET_OS_TV
  34. @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin;
  35. @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin;
  36. @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin;
  37. @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin;
  38. @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin;
  39. @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin;
  40. @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins;
  41. @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins;
  42. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide NS_AVAILABLE_IOS(11.0);
  43. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
  44. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
  45. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
  46. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
  47. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
  48. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
  49. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
  50. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
  51. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
  52. @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);
  53. #endif
  54. /**
  55. * a key to associate with this view
  56. */
  57. @property (nonatomic, strong) id mas_key;
  58. /**
  59. * Finds the closest common superview between this view and another view
  60. *
  61. * @param view other view
  62. *
  63. * @return returns nil if common superview could not be found
  64. */
  65. - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
  66. /**
  67. * Creates a MASConstraintMaker with the callee view.
  68. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing
  69. *
  70. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  71. *
  72. * @return Array of created MASConstraints
  73. */
  74. - (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  75. /**
  76. * Creates a MASConstraintMaker with the callee view.
  77. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
  78. * If an existing constraint exists then it will be updated instead.
  79. *
  80. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  81. *
  82. * @return Array of created/updated MASConstraints
  83. */
  84. - (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  85. /**
  86. * Creates a MASConstraintMaker with the callee view.
  87. * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
  88. * All constraints previously installed for the view will be removed.
  89. *
  90. * @param block scope within which you can build up the constraints which you wish to apply to the view.
  91. *
  92. * @return Array of created/updated MASConstraints
  93. */
  94. - (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
  95. @end