View+MASAdditions.h 3.7 KB

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