NSArray+PureLayout.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // NSArray+PureLayout.h
  3. // https://github.com/PureLayout/PureLayout
  4. //
  5. // Copyright (c) 2012 Richard Turton
  6. // Copyright (c) 2013-2015 Tyler Fox
  7. //
  8. // This code is distributed under the terms and conditions of the MIT license.
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy
  11. // of this software and associated documentation files (the "Software"), to
  12. // deal in the Software without restriction, including without limitation the
  13. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  14. // sell copies of the Software, and to permit persons to whom the Software is
  15. // furnished to do so, subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  26. // IN THE SOFTWARE.
  27. //
  28. #import "PureLayoutDefines.h"
  29. PL__ASSUME_NONNULL_BEGIN
  30. #pragma mark NSArray+PureLayout
  31. /**
  32. A category on NSArray that provides a simple yet powerful interface to:
  33. - Manage an array of Auto Layout constraints
  34. - Apply constraints to an array of views
  35. */
  36. @interface NSArray (PureLayout)
  37. #pragma mark Array of Constraints
  38. /** Activates the constraints in this array. */
  39. - (void)autoInstallConstraints;
  40. /** Deactivates the constraints in this array. */
  41. - (void)autoRemoveConstraints;
  42. #if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
  43. /** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */
  44. - (instancetype)autoIdentifyConstraints:(NSString *)identifier;
  45. #endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
  46. #pragma mark Array of Views
  47. /** Aligns views in this array to one another along a given edge. */
  48. - (PL__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge;
  49. /** Aligns views in this array to one another along a given axis. */
  50. - (PL__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis;
  51. /** Matches a given dimension of all the views in this array. */
  52. - (PL__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension;
  53. /** Sets the given dimension of all the views in this array to a given size. */
  54. - (PL__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
  55. /** Sets all of the views in this array to a given size. */
  56. - (PL__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size;
  57. /** Distributes the views in this array equally along the selected axis in their superview.
  58. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */
  59. - (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
  60. alignedTo:(ALAttribute)alignment
  61. withFixedSpacing:(CGFloat)spacing;
  62. /** Distributes the views in this array equally along the selected axis in their superview.
  63. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */
  64. - (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
  65. alignedTo:(ALAttribute)alignment
  66. withFixedSpacing:(CGFloat)spacing
  67. insetSpacing:(BOOL)shouldSpaceInsets;
  68. /** Distributes the views in this array equally along the selected axis in their superview.
  69. Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */
  70. - (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
  71. alignedTo:(ALAttribute)alignment
  72. withFixedSpacing:(CGFloat)spacing
  73. insetSpacing:(BOOL)shouldSpaceInsets
  74. matchedSizes:(BOOL)shouldMatchSizes;
  75. /** Distributes the views in this array equally along the selected axis in their superview.
  76. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */
  77. - (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
  78. alignedTo:(ALAttribute)alignment
  79. withFixedSize:(CGFloat)size;
  80. /** Distributes the views in this array equally along the selected axis in their superview.
  81. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */
  82. - (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
  83. alignedTo:(ALAttribute)alignment
  84. withFixedSize:(CGFloat)size
  85. insetSpacing:(BOOL)shouldSpaceInsets;
  86. @end
  87. PL__ASSUME_NONNULL_END