View+MASAdditions.h 4.0 KB

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