NSLayoutConstraint+PureLayout.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // NSLayoutConstraint+PureLayout.h
  3. // https://github.com/PureLayout/PureLayout
  4. //
  5. // Copyright (c) 2013-2015 Tyler Fox
  6. //
  7. // This code is distributed under the terms and conditions of the MIT license.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to
  11. // deal in the Software without restriction, including without limitation the
  12. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  13. // sell copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  25. // IN THE SOFTWARE.
  26. //
  27. #import "PureLayoutDefines.h"
  28. PL__ASSUME_NONNULL_BEGIN
  29. #pragma mark NSLayoutConstraint+PureLayout
  30. /**
  31. A category on NSLayoutConstraint that allows constraints to be easily installed & removed.
  32. */
  33. @interface NSLayoutConstraint (PureLayout)
  34. #pragma mark Batch Constraint Creation
  35. /** Creates all of the constraints in the block, then installs (activates) them all at once.
  36. All constraints created from calls to the PureLayout API in the block are returned in a single array.
  37. This may be more efficient than installing (activating) each constraint one-by-one. */
  38. + (PL__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(__attribute__((noescape)) ALConstraintsBlock)block;
  39. /** Creates all of the constraints in the block but prevents them from being automatically installed (activated).
  40. All constraints created from calls to the PureLayout API in the block are returned in a single array. */
  41. + (PL__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(__attribute__((noescape)) ALConstraintsBlock)block;
  42. #pragma mark Set Priority For Constraints
  43. /** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block.
  44. NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */
  45. + (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(__attribute__((noescape)) ALConstraintsBlock)block;
  46. #pragma mark Identify Constraints
  47. #if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
  48. /** Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
  49. NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */
  50. + (void)autoSetIdentifier:(NSString *)identifier forConstraints:(__attribute__((noescape)) ALConstraintsBlock)block;
  51. /** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */
  52. - (instancetype)autoIdentify:(NSString *)identifier;
  53. #endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
  54. #pragma mark Install & Remove Constraints
  55. /** Activates the the constraint. */
  56. - (void)autoInstall;
  57. /** Deactivates the constraint. */
  58. - (void)autoRemove;
  59. @end
  60. PL__ASSUME_NONNULL_END