Release 0.1.0
This commit is contained in:
1 parent
fae05a1709
commit
c8bd9b7435
230 files changed
+17003
-15
No files matched your search
+9
@@ -0,0 +1,9 @@
|
||||
This code is distributed under the terms and conditions of the MIT license.
|
||||
|
||||
Copyright (c) 2014-2015 Tyler Fox
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
//
|
||||
// ALView+PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
#pragma mark - ALView+PureLayout
|
||||
|
||||
/**
|
||||
A category on UIView/NSView that provides a simple yet powerful interface for creating Auto Layout constraints.
|
||||
*/
|
||||
@interface ALView (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Factory & Initializer Methods
|
||||
|
||||
/** Creates and returns a new view that does not convert the autoresizing mask into constraints. */
|
||||
+ (instancetype)newAutoLayoutView;
|
||||
|
||||
/** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */
|
||||
- (instancetype)initForAutoLayout;
|
||||
|
||||
|
||||
#pragma mark Create Constraints Without Installing
|
||||
|
||||
/** Prevents constraints created in the given constraints block from being automatically installed (activated).
|
||||
The constraints created from calls to the PureLayout API in the block are returned in a single array. */
|
||||
+ (NSArray *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block;
|
||||
|
||||
|
||||
#pragma mark Set Priority For Constraints
|
||||
|
||||
/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block.
|
||||
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */
|
||||
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block;
|
||||
|
||||
|
||||
#pragma mark Set Identifier For Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
|
||||
NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */
|
||||
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Center & Align in Superview
|
||||
|
||||
/** Centers the view in its superview. */
|
||||
- (NSArray *)autoCenterInSuperview;
|
||||
|
||||
/** Aligns the view to the same axis of its superview. */
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Centers the view in its superview's margins. Available in iOS 8.0 and later. */
|
||||
- (NSArray *)autoCenterInSuperviewMargins;
|
||||
|
||||
/** Aligns the view to the corresponding margin axis of its superview. Available in iOS 8.0 and later. */
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges to Superview
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview with an inset. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview with the given edge insets. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets;
|
||||
|
||||
/** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Pins the given edge of the view to the corresponding margin of its superview. Available in iOS 8.0 and later. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge;
|
||||
|
||||
/** Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum. Available in iOS 8.0 and later. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the edges of the view to the margins of its superview. Available in iOS 8.0 and later. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewMargins;
|
||||
|
||||
/** Pins 3 of the 4 edges of the view to the margins of its superview excluding one edge. Available in iOS 8.0 and later. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView;
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Align Axes
|
||||
|
||||
/** Aligns an axis of the view to the same axis of another view. */
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView;
|
||||
|
||||
/** Aligns an axis of the view to the same axis of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
|
||||
#pragma mark Match Dimensions
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView;
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Matches a dimension of the view to a multiple of a given dimension of another view. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier;
|
||||
|
||||
/** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Set Dimensions
|
||||
|
||||
/** Sets the view to a specific size. */
|
||||
- (NSArray *)autoSetDimensionsToSize:(CGSize)size;
|
||||
|
||||
/** Sets the given dimension of the view to a specific size. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
|
||||
/** Sets the given dimension of the view to a specific size as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Set Content Compression Resistance & Hugging
|
||||
|
||||
/** Sets the priority of content compression resistance for an axis.
|
||||
NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */
|
||||
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis;
|
||||
|
||||
/** Sets the priority of content hugging for an axis.
|
||||
NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */
|
||||
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis;
|
||||
|
||||
|
||||
#pragma mark Constrain Any Attributes
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with a multiplier. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with a multiplier as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Pin to Layout Guides (iOS only)
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the top edge of the view to the top layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
|
||||
#pragma mark Deprecated Methods
|
||||
|
||||
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
|
||||
Removes all explicit constraints that affect the view.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */
|
||||
- (void)autoRemoveConstraintsAffectingView __attribute__((deprecated));
|
||||
|
||||
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
|
||||
Removes all constraints that affect the view, optionally including implicit constraints.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */
|
||||
- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated));
|
||||
|
||||
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
|
||||
Recursively removes all explicit constraints that affect the view and its subviews.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */
|
||||
- (void)autoRemoveConstraintsAffectingViewAndSubviews __attribute__((deprecated));
|
||||
|
||||
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
|
||||
Recursively removes all constraints from the view and its subviews, optionally including implicit constraints.
|
||||
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
|
||||
NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */
|
||||
- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated));
|
||||
|
||||
@end
|
||||
+1102
File diff suppressed because it is too large.
Load diff
+107
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// NSArray+PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
#pragma mark - NSArray+PureLayout
|
||||
|
||||
/**
|
||||
A category on NSArray that provides a simple yet powerful interface to:
|
||||
- Manage an array of Auto Layout constraints
|
||||
- Apply constraints to an array of views
|
||||
*/
|
||||
@interface NSArray (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Array of Constraints
|
||||
|
||||
/** Activates the constraints in this array. */
|
||||
- (void)autoInstallConstraints;
|
||||
|
||||
/** Deactivates the constraints in this array. */
|
||||
- (void)autoRemoveConstraints;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */
|
||||
- (instancetype)autoIdentifyConstraints:(NSString *)identifier;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Array of Views
|
||||
|
||||
/** Aligns views in this array to one another along a given edge. */
|
||||
- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge;
|
||||
|
||||
/** Aligns views in this array to one another along a given axis. */
|
||||
- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis;
|
||||
|
||||
/** Matches a given dimension of all the views in this array. */
|
||||
- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension;
|
||||
|
||||
/** Sets the given dimension of all the views in this array to a given size. */
|
||||
- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
|
||||
/** Sets all of the views in this array to a given size. */
|
||||
- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size;
|
||||
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. 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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. 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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
matchedSizes:(BOOL)shouldMatchSizes;
|
||||
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview. 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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
insetSpacing:(BOOL)shouldSpaceInsets;
|
||||
|
||||
@end
|
||||
+506
@@ -0,0 +1,506 @@
|
||||
//
|
||||
// NSArray+PureLayout.m
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
#import "PureLayout+Internal.h"
|
||||
|
||||
|
||||
#pragma mark - NSArray+PureLayout
|
||||
|
||||
@implementation NSArray (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Array of Constraints
|
||||
|
||||
/**
|
||||
Activates the constraints in this array.
|
||||
*/
|
||||
- (void)autoInstallConstraints
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) {
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[ALView al_applyGlobalStateToConstraint:object];
|
||||
}
|
||||
}
|
||||
if ([ALView al_preventAutomaticConstraintInstallation]) {
|
||||
[[ALView al_currentArrayOfCreatedConstraints] addObjectsFromArray:self];
|
||||
} else {
|
||||
[NSLayoutConstraint activateConstraints:self];
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[((NSLayoutConstraint *)object) autoInstall];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Deactivates the constraints in this array.
|
||||
*/
|
||||
- (void)autoRemoveConstraints
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) {
|
||||
[NSLayoutConstraint deactivateConstraints:self];
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[((NSLayoutConstraint *)object) autoRemove];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later.
|
||||
The identifier will be printed along with each constraint's description.
|
||||
This is helpful to document the constraints' purpose and aid in debugging.
|
||||
|
||||
@param identifier A string used to identify the constraints in this array.
|
||||
@return This array.
|
||||
*/
|
||||
- (instancetype)autoIdentifyConstraints:(NSString *)identifier
|
||||
{
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[((NSLayoutConstraint *)object) autoIdentify:identifier];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Array of Views
|
||||
|
||||
/**
|
||||
Aligns views in this array to one another along a given edge.
|
||||
Note: This array must contain at least 2 views, and all views must share a common superview.
|
||||
|
||||
@param edge The edge to which the views will be aligned.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
[constraints addObject:[view autoPinEdge:edge toEdge:edge ofView:previousView]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Aligns views in this array to one another along a given axis.
|
||||
Note: This array must contain at least 2 views, and all views must share a common superview.
|
||||
|
||||
@param axis The axis to which the views will be aligned.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
[constraints addObject:[view autoAlignAxis:axis toSameAxisOfView:previousView]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a given dimension of all the views in this array.
|
||||
Note: This array must contain at least 2 views, and all views must share a common superview.
|
||||
|
||||
@param dimension The dimension to match for all of the views.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
[constraints addObject:[view autoMatchDimension:dimension toDimension:dimension ofView:previousView]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the given dimension of all the views in this array to a given size.
|
||||
Note: This array must contain at least 1 view.
|
||||
|
||||
@param dimension The dimension of each of the views to set.
|
||||
@param size The size to set the given dimension of each view to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[constraints addObject:[view autoSetDimension:dimension toSize:size]];
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets all of the views in this array to a given size.
|
||||
Note: This array must contain at least 1 view.
|
||||
|
||||
@param size The size to set each view's dimensions to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size
|
||||
{
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]];
|
||||
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them,
|
||||
including from the first and last views to their superview.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
{
|
||||
return [self autoDistributeViewsAlongAxis:axis
|
||||
alignedTo:alignment
|
||||
withFixedSpacing:spacing
|
||||
insetSpacing:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them.
|
||||
The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
{
|
||||
return [self autoDistributeViewsAlongAxis:axis
|
||||
alignedTo:alignment
|
||||
withFixedSpacing:spacing
|
||||
insetSpacing:shouldSpaceInsets
|
||||
matchedSizes:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will have fixed spacing between them, and can optionally be constrained to the same size in the dimension along the axis.
|
||||
The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@param shouldMatchSizes Whether all views will be constrained to be the same size in the dimension along the axis.
|
||||
NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous!
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
matchedSizes:(BOOL)shouldMatchSizes
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute.");
|
||||
ALDimension matchedDimension;
|
||||
ALEdge firstEdge, lastEdge;
|
||||
switch (axis) {
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
matchedDimension = ALDimensionWidth;
|
||||
firstEdge = ALEdgeLeading;
|
||||
lastEdge = ALEdgeTrailing;
|
||||
break;
|
||||
case ALAxisVertical:
|
||||
matchedDimension = ALDimensionHeight;
|
||||
firstEdge = ALEdgeTop;
|
||||
lastEdge = ALEdgeBottom;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
return nil;
|
||||
}
|
||||
CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
// Second, Third, ... View
|
||||
[constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]];
|
||||
if (shouldMatchSizes) {
|
||||
[constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]];
|
||||
}
|
||||
[constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]];
|
||||
}
|
||||
else {
|
||||
// First view
|
||||
[constraints addObject:[view autoPinEdgeToSuperviewEdge:firstEdge withInset:leadingSpacing]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
if (previousView) {
|
||||
// Last View
|
||||
[constraints addObject:[previousView autoPinEdgeToSuperviewEdge:lastEdge withInset:trailingSpacing]];
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them,
|
||||
including from the first and last views to their superview.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param size The fixed size of each view in the dimension along the given axis.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
{
|
||||
return [self autoDistributeViewsAlongAxis:axis
|
||||
alignedTo:alignment
|
||||
withFixedSize:size
|
||||
insetSpacing:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them.
|
||||
The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param size The fixed size of each view in the dimension along the given axis.
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute.");
|
||||
ALDimension fixedDimension;
|
||||
NSLayoutAttribute attribute;
|
||||
switch (axis) {
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
fixedDimension = ALDimensionWidth;
|
||||
attribute = NSLayoutAttributeCenterX;
|
||||
break;
|
||||
case ALAxisVertical:
|
||||
fixedDimension = ALDimensionHeight;
|
||||
attribute = NSLayoutAttributeCenterY;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
return nil;
|
||||
}
|
||||
#if TARGET_OS_IPHONE
|
||||
# if !defined(PURELAYOUT_APP_EXTENSIONS)
|
||||
BOOL isRightToLeftLayout = [[UIApplication sharedApplication] userInterfaceLayoutDirection] == UIUserInterfaceLayoutDirectionRightToLeft;
|
||||
# else
|
||||
// App Extensions may not access -[UIApplication sharedApplication]; fall back to checking the bundle's preferred localization character direction
|
||||
BOOL isRightToLeftLayout = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft;
|
||||
# endif /* !defined(PURELAYOUT_APP_EXTENSIONS) */
|
||||
#else
|
||||
BOOL isRightToLeftLayout = [[NSApplication sharedApplication] userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft;
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally
|
||||
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
NSArray *views = [self al_copyViewsOnly];
|
||||
NSUInteger numberOfViews = [views count];
|
||||
ALView *commonSuperview = [views al_commonSuperviewOfViews];
|
||||
ALView *previousView = nil;
|
||||
for (NSUInteger i = 0; i < numberOfViews; i++) {
|
||||
ALView *view = shouldFlipOrder ? views[numberOfViews - i - 1] : views[i];
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[constraints addObject:[view autoSetDimension:fixedDimension toSize:size]];
|
||||
CGFloat multiplier, constant;
|
||||
if (shouldSpaceInsets) {
|
||||
multiplier = (i * 2.0 + 2.0) / (numberOfViews + 1.0);
|
||||
constant = (multiplier - 1.0) * size / 2.0;
|
||||
} else {
|
||||
multiplier = (i * 2.0) / (numberOfViews - 1.0);
|
||||
constant = (-multiplier + 1.0) * size / 2.0;
|
||||
}
|
||||
// If the multiplier is very close to 0, set it to the minimum value to prevent the second item in the constraint from being lost. Filed as rdar://19168380
|
||||
if (fabs(multiplier) < kMULTIPLIER_MIN_VALUE) {
|
||||
multiplier = kMULTIPLIER_MIN_VALUE;
|
||||
}
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant];
|
||||
[constraint autoInstall];
|
||||
[constraints addObject:constraint];
|
||||
if (previousView) {
|
||||
[constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
#pragma mark Internal Helper Methods
|
||||
|
||||
/**
|
||||
Returns the common superview for the views in this array.
|
||||
Raises an exception if the views in this array do not share a common superview.
|
||||
|
||||
@return The common superview for the views in this array.
|
||||
*/
|
||||
- (ALView *)al_commonSuperviewOfViews
|
||||
{
|
||||
ALView *commonSuperview = nil;
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
if (previousView) {
|
||||
commonSuperview = [view al_commonSuperviewWithView:commonSuperview];
|
||||
} else {
|
||||
commonSuperview = view;
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy.");
|
||||
return commonSuperview;
|
||||
}
|
||||
|
||||
/**
|
||||
Determines whether this array contains a minimum number of views.
|
||||
|
||||
@param minimumNumberOfViews The minimum number of views to check for.
|
||||
@return YES if this array contains at least the minimum number of views, NO otherwise.
|
||||
*/
|
||||
- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews
|
||||
{
|
||||
NSUInteger numberOfViews = 0;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
numberOfViews++;
|
||||
if (numberOfViews >= minimumNumberOfViews) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
return numberOfViews >= minimumNumberOfViews;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a copy of this array containing only the view objects in it.
|
||||
|
||||
@return A new array containing only the views that are in this array.
|
||||
*/
|
||||
- (NSArray *)al_copyViewsOnly
|
||||
{
|
||||
NSMutableArray *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]];
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
[viewsOnlyArray addObject:object];
|
||||
}
|
||||
}
|
||||
return viewsOnlyArray;
|
||||
}
|
||||
|
||||
@end
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// NSLayoutConstraint+PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
#pragma mark - NSLayoutConstraint+PureLayout
|
||||
|
||||
/**
|
||||
A category on NSLayoutConstraint that allows constraints to be easily installed & removed.
|
||||
*/
|
||||
@interface NSLayoutConstraint (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Install & Remove Constraints
|
||||
|
||||
/** Activates the the constraint. */
|
||||
- (void)autoInstall;
|
||||
|
||||
/** Deactivates the constraint. */
|
||||
- (void)autoRemove;
|
||||
|
||||
|
||||
#pragma mark Identify Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */
|
||||
- (instancetype)autoIdentify:(NSString *)identifier;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
@end
|
||||
+314
@@ -0,0 +1,314 @@
|
||||
//
|
||||
// NSLayoutConstraint+PureLayout.m
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "PureLayout+Internal.h"
|
||||
|
||||
|
||||
#pragma mark - NSLayoutConstraint+PureLayout
|
||||
|
||||
@implementation NSLayoutConstraint (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Installing & Removing Constraints
|
||||
|
||||
/**
|
||||
Activates the constraint.
|
||||
*/
|
||||
- (void)autoInstall
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([self respondsToSelector:@selector(setActive:)]) {
|
||||
[ALView al_applyGlobalStateToConstraint:self];
|
||||
if ([ALView al_preventAutomaticConstraintInstallation]) {
|
||||
[[ALView al_currentArrayOfCreatedConstraints] addObject:self];
|
||||
} else {
|
||||
self.active = YES;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem.");
|
||||
if (self.firstItem) {
|
||||
if (self.secondItem) {
|
||||
NSAssert([self.firstItem isKindOfClass:[ALView class]] && [self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if both items are views.");
|
||||
ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem];
|
||||
[commonSuperview al_addConstraint:self];
|
||||
} else {
|
||||
NSAssert([self.firstItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view.");
|
||||
[self.firstItem al_addConstraint:self];
|
||||
}
|
||||
} else {
|
||||
NSAssert([self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view.");
|
||||
[self.secondItem al_addConstraint:self];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Deactivates the constraint.
|
||||
*/
|
||||
- (void)autoRemove
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([self respondsToSelector:@selector(setActive:)]) {
|
||||
self.active = NO;
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
if (self.secondItem) {
|
||||
ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem];
|
||||
while (commonSuperview) {
|
||||
if ([commonSuperview.constraints containsObject:self]) {
|
||||
[commonSuperview removeConstraint:self];
|
||||
return;
|
||||
}
|
||||
commonSuperview = commonSuperview.superview;
|
||||
}
|
||||
}
|
||||
else {
|
||||
[self.firstItem removeConstraint:self];
|
||||
return;
|
||||
}
|
||||
NSAssert(nil, @"Failed to remove constraint: %@", self);
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Identify Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/**
|
||||
Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later.
|
||||
The identifier will be printed along with the constraint's description.
|
||||
This is helpful to document a constraint's purpose and aid in debugging.
|
||||
|
||||
@param identifier A string used to identify this constraint.
|
||||
@return This constraint.
|
||||
*/
|
||||
- (instancetype)autoIdentify:(NSString *)identifier
|
||||
{
|
||||
if ([self respondsToSelector:@selector(setIdentifier:)]) {
|
||||
self.identifier = identifier;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Internal Methods
|
||||
|
||||
/**
|
||||
Returns the corresponding NSLayoutAttribute for the given ALAttribute.
|
||||
|
||||
@return The layout attribute for the given ALAttribute.
|
||||
*/
|
||||
+ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute
|
||||
{
|
||||
NSLayoutAttribute layoutAttribute = NSLayoutAttributeNotAnAttribute;
|
||||
switch (attribute) {
|
||||
case ALEdgeLeft:
|
||||
layoutAttribute = NSLayoutAttributeLeft;
|
||||
break;
|
||||
case ALEdgeRight:
|
||||
layoutAttribute = NSLayoutAttributeRight;
|
||||
break;
|
||||
case ALEdgeTop:
|
||||
layoutAttribute = NSLayoutAttributeTop;
|
||||
break;
|
||||
case ALEdgeBottom:
|
||||
layoutAttribute = NSLayoutAttributeBottom;
|
||||
break;
|
||||
case ALEdgeLeading:
|
||||
layoutAttribute = NSLayoutAttributeLeading;
|
||||
break;
|
||||
case ALEdgeTrailing:
|
||||
layoutAttribute = NSLayoutAttributeTrailing;
|
||||
break;
|
||||
case ALDimensionWidth:
|
||||
layoutAttribute = NSLayoutAttributeWidth;
|
||||
break;
|
||||
case ALDimensionHeight:
|
||||
layoutAttribute = NSLayoutAttributeHeight;
|
||||
break;
|
||||
case ALAxisVertical:
|
||||
layoutAttribute = NSLayoutAttributeCenterX;
|
||||
break;
|
||||
case ALAxisHorizontal:
|
||||
layoutAttribute = NSLayoutAttributeCenterY;
|
||||
break;
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
layoutAttribute = NSLayoutAttributeBaseline;
|
||||
break;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisFirstBaseline is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeFirstBaseline;
|
||||
break;
|
||||
case ALMarginLeft:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeftMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeLeftMargin;
|
||||
break;
|
||||
case ALMarginRight:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeRightMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeRightMargin;
|
||||
break;
|
||||
case ALMarginTop:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTopMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeTopMargin;
|
||||
break;
|
||||
case ALMarginBottom:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeBottomMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeBottomMargin;
|
||||
break;
|
||||
case ALMarginLeading:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeadingMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeLeadingMargin;
|
||||
break;
|
||||
case ALMarginTrailing:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTrailingMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeTrailingMargin;
|
||||
break;
|
||||
case ALMarginAxisVertical:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisVerticalMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeCenterXWithinMargins;
|
||||
break;
|
||||
case ALMarginAxisHorizontal:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisHorizontalMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeCenterYWithinMargins;
|
||||
break;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAttribute.");
|
||||
break;
|
||||
}
|
||||
return layoutAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the corresponding ALLayoutConstraintAxis for the given ALAxis.
|
||||
|
||||
@return The constraint axis for the given axis.
|
||||
*/
|
||||
+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis
|
||||
{
|
||||
ALLayoutConstraintAxis constraintAxis;
|
||||
switch (axis) {
|
||||
case ALAxisVertical:
|
||||
constraintAxis = ALLayoutConstraintAxisVertical;
|
||||
break;
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
constraintAxis = ALLayoutConstraintAxisHorizontal;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
constraintAxis = ALLayoutConstraintAxisHorizontal; // default to a random value to satisfy the compiler
|
||||
break;
|
||||
}
|
||||
return constraintAxis;
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Returns the corresponding margin for the given edge.
|
||||
|
||||
@param edge The edge to convert to the corresponding margin.
|
||||
@return The margin for the given edge.
|
||||
*/
|
||||
+ (ALMargin)al_marginForEdge:(ALEdge)edge
|
||||
{
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
ALMargin margin;
|
||||
switch (edge) {
|
||||
case ALEdgeLeft:
|
||||
margin = ALMarginLeft;
|
||||
break;
|
||||
case ALEdgeRight:
|
||||
margin = ALMarginRight;
|
||||
break;
|
||||
case ALEdgeTop:
|
||||
margin = ALMarginTop;
|
||||
break;
|
||||
case ALEdgeBottom:
|
||||
margin = ALMarginBottom;
|
||||
break;
|
||||
case ALEdgeLeading:
|
||||
margin = ALMarginLeading;
|
||||
break;
|
||||
case ALEdgeTrailing:
|
||||
margin = ALMarginTrailing;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALEdge.");
|
||||
margin = ALMarginLeft; // default to a random value to satisfy the compiler
|
||||
break;
|
||||
}
|
||||
return margin;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the corresponding margin axis for the given axis.
|
||||
|
||||
@param axis The axis to convert to the corresponding margin axis.
|
||||
@return The margin axis for the given axis.
|
||||
*/
|
||||
+ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
ALMarginAxis marginAxis;
|
||||
switch (axis) {
|
||||
case ALAxisVertical:
|
||||
marginAxis = ALMarginAxisVertical;
|
||||
break;
|
||||
case ALAxisHorizontal:
|
||||
marginAxis = ALMarginAxisHorizontal;
|
||||
break;
|
||||
case ALAxisBaseline:
|
||||
case ALAxisFirstBaseline:
|
||||
NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes.");
|
||||
marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler
|
||||
break;
|
||||
}
|
||||
return marginAxis;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// PureLayout+Internal.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
/** A constant that represents the smallest valid positive value for the multiplier of a constraint,
|
||||
since a value of 0 will cause the second item to be lost in the internal auto layout engine. */
|
||||
static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems
|
||||
|
||||
|
||||
/**
|
||||
A category that exposes the internal (private) helper methods of the ALView+PureLayout category.
|
||||
*/
|
||||
@interface ALView (PureLayoutInternal)
|
||||
|
||||
+ (BOOL)al_preventAutomaticConstraintInstallation;
|
||||
+ (NSMutableArray *)al_currentArrayOfCreatedConstraints;
|
||||
+ (BOOL)al_isExecutingPriorityConstraintsBlock;
|
||||
+ (ALLayoutPriority)al_currentGlobalConstraintPriority;
|
||||
+ (NSString *)al_currentGlobalConstraintIdentifier;
|
||||
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint;
|
||||
- (void)al_addConstraint:(NSLayoutConstraint *)constraint;
|
||||
- (ALView *)al_commonSuperviewWithView:(ALView *)otherView;
|
||||
- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
A category that exposes the internal (private) helper methods of the NSArray+PureLayout category.
|
||||
*/
|
||||
@interface NSArray (PureLayoutInternal)
|
||||
|
||||
- (ALView *)al_commonSuperviewOfViews;
|
||||
- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews;
|
||||
- (NSArray *)al_copyViewsOnly;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
A category that exposes the internal (private) helper methods of the NSLayoutConstraint+PureLayout category.
|
||||
*/
|
||||
@interface NSLayoutConstraint (PureLayoutInternal)
|
||||
|
||||
+ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute;
|
||||
+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
+ (ALMargin)al_marginForEdge:(ALEdge)edge;
|
||||
+ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
@end
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef PureLayout_h
|
||||
#define PureLayout_h
|
||||
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
|
||||
#endif /* PureLayout_h */
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
//
|
||||
// PureLayoutDefines.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef PureLayoutDefines_h
|
||||
#define PureLayoutDefines_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// Define some preprocessor macros to check for a minimum Base SDK. These are used to prevent compile-time errors in older versions of Xcode.
|
||||
#define __PureLayout_MinBaseSDK_iOS_8_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1)
|
||||
#define __PureLayout_MinBaseSDK_OSX_10_10 (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9)
|
||||
|
||||
// Define some preprocessor macros to check for a minimum System Version. These are used to prevent runtime crashes on older versions of iOS/OS X.
|
||||
#define __PureLayout_MinSysVer_iOS_7_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
|
||||
#define __PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
|
||||
#define __PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4)
|
||||
|
||||
// Define generic AL-prefixed macros for the types/constants/etc that have slight naming variations across iOS and OS X, which allows the same code to be platform-independent
|
||||
#if TARGET_OS_IPHONE
|
||||
# import <UIKit/UIKit.h>
|
||||
# define ALView UIView
|
||||
# define ALEdgeInsets UIEdgeInsets
|
||||
# define ALEdgeInsetsZero UIEdgeInsetsZero
|
||||
# define ALEdgeInsetsMake UIEdgeInsetsMake
|
||||
# define ALLayoutConstraintAxis UILayoutConstraintAxis
|
||||
# define ALLayoutConstraintOrientation ALLayoutConstraintAxis
|
||||
# define ALLayoutConstraintAxisHorizontal UILayoutConstraintAxisHorizontal
|
||||
# define ALLayoutConstraintAxisVertical UILayoutConstraintAxisVertical
|
||||
# define ALLayoutConstraintOrientationHorizontal ALLayoutConstraintAxisHorizontal
|
||||
# define ALLayoutConstraintOrientationVertical ALLayoutConstraintAxisVertical
|
||||
# define ALLayoutPriority UILayoutPriority
|
||||
# define ALLayoutPriorityRequired UILayoutPriorityRequired
|
||||
# define ALLayoutPriorityDefaultHigh UILayoutPriorityDefaultHigh
|
||||
# define ALLayoutPriorityDefaultLow UILayoutPriorityDefaultLow
|
||||
# define ALLayoutPriorityFittingSizeLevel UILayoutPriorityFittingSizeLevel
|
||||
# define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel
|
||||
#else
|
||||
# import <Cocoa/Cocoa.h>
|
||||
# define ALView NSView
|
||||
# define ALEdgeInsets NSEdgeInsets
|
||||
# define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0)
|
||||
# define ALEdgeInsetsMake NSEdgeInsetsMake
|
||||
# define ALLayoutConstraintOrientation NSLayoutConstraintOrientation
|
||||
# define ALLayoutConstraintAxis ALLayoutConstraintOrientation
|
||||
# define ALLayoutConstraintOrientationHorizontal NSLayoutConstraintOrientationHorizontal
|
||||
# define ALLayoutConstraintOrientationVertical NSLayoutConstraintOrientationVertical
|
||||
# define ALLayoutConstraintAxisHorizontal ALLayoutConstraintOrientationHorizontal
|
||||
# define ALLayoutConstraintAxisVertical ALLayoutConstraintOrientationVertical
|
||||
# define ALLayoutPriority NSLayoutPriority
|
||||
# define ALLayoutPriorityRequired NSLayoutPriorityRequired
|
||||
# define ALLayoutPriorityDefaultHigh NSLayoutPriorityDefaultHigh
|
||||
# define ALLayoutPriorityDefaultLow NSLayoutPriorityDefaultLow
|
||||
# define ALLayoutPriorityFittingSizeCompression NSLayoutPriorityFittingSizeCompression
|
||||
# define ALLayoutPriorityFittingSizeLevel ALLayoutPriorityFittingSizeCompression
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
|
||||
#pragma mark PureLayout Attributes
|
||||
|
||||
/** Constants that represent edges of a view. */
|
||||
typedef NS_ENUM(NSInteger, ALEdge) {
|
||||
/** The left edge of the view. */
|
||||
ALEdgeLeft = NSLayoutAttributeLeft,
|
||||
/** The right edge of the view. */
|
||||
ALEdgeRight = NSLayoutAttributeRight,
|
||||
/** The top edge of the view. */
|
||||
ALEdgeTop = NSLayoutAttributeTop,
|
||||
/** The bottom edge of the view. */
|
||||
ALEdgeBottom = NSLayoutAttributeBottom,
|
||||
/** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */
|
||||
ALEdgeLeading = NSLayoutAttributeLeading,
|
||||
/** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */
|
||||
ALEdgeTrailing = NSLayoutAttributeTrailing
|
||||
};
|
||||
|
||||
/** Constants that represent dimensions of a view. */
|
||||
typedef NS_ENUM(NSInteger, ALDimension) {
|
||||
/** The width of the view. */
|
||||
ALDimensionWidth = NSLayoutAttributeWidth,
|
||||
/** The height of the view. */
|
||||
ALDimensionHeight = NSLayoutAttributeHeight
|
||||
};
|
||||
|
||||
/** Constants that represent axes of a view. */
|
||||
typedef NS_ENUM(NSInteger, ALAxis) {
|
||||
/** A vertical line through the middle of the view's left and right edges. */
|
||||
ALAxisVertical = NSLayoutAttributeCenterX,
|
||||
/** A horizontal line through the middle of the view's top and bottom edges. */
|
||||
ALAxisHorizontal = NSLayoutAttributeCenterY,
|
||||
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
|
||||
ALAxisBaseline = NSLayoutAttributeBaseline,
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */
|
||||
ALAxisLastBaseline = ALAxisBaseline,
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
/** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */
|
||||
ALAxisFirstBaseline = NSLayoutAttributeFirstBaseline
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
};
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Constants that represent layout margins of a view. Available in iOS 8.0 and later. */
|
||||
typedef NS_ENUM(NSInteger, ALMargin) {
|
||||
/** The left margin of the view, based on the view's layoutMargins left inset. */
|
||||
ALMarginLeft = NSLayoutAttributeLeftMargin,
|
||||
/** The right margin of the view, based on the view's layoutMargins right inset. */
|
||||
ALMarginRight = NSLayoutAttributeRightMargin,
|
||||
/** The top margin of the view, based on the view's layoutMargins top inset. */
|
||||
ALMarginTop = NSLayoutAttributeTopMargin,
|
||||
/** The bottom margin of the view, based on the view's layoutMargins bottom inset. */
|
||||
ALMarginBottom = NSLayoutAttributeBottomMargin,
|
||||
/** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALMarginLeading = NSLayoutAttributeLeadingMargin,
|
||||
/** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALMarginTrailing = NSLayoutAttributeTrailingMargin
|
||||
};
|
||||
|
||||
/** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */
|
||||
typedef NS_ENUM(NSInteger, ALMarginAxis) {
|
||||
/** A vertical line through the middle of the view's left and right margins. */
|
||||
ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins,
|
||||
/** A horizontal line through the middle of the view's top and bottom margins. */
|
||||
ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins
|
||||
};
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
/** An attribute of a view that can be used in auto layout constraints. These constants are identical to the more specific enum types:
|
||||
ALEdge, ALAxis, ALDimension, ALMargin, ALMarginAxis. It is safe to cast a more specific enum type to the ALAttribute type. */
|
||||
typedef NS_ENUM(NSInteger, ALAttribute) {
|
||||
/** The left edge of the view. */
|
||||
ALAttributeLeft = ALEdgeLeft,
|
||||
/** The right edge of the view. */
|
||||
ALAttributeRight = ALEdgeRight,
|
||||
/** The top edge of the view. */
|
||||
ALAttributeTop = ALEdgeTop,
|
||||
/** The bottom edge of the view. */
|
||||
ALAttributeBottom = ALEdgeBottom,
|
||||
/** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */
|
||||
ALAttributeLeading = ALEdgeLeading,
|
||||
/** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */
|
||||
ALAttributeTrailing = ALEdgeTrailing,
|
||||
/** The width of the view. */
|
||||
ALAttributeWidth = ALDimensionWidth,
|
||||
/** The height of the view. */
|
||||
ALAttributeHeight = ALDimensionHeight,
|
||||
/** A vertical line through the middle of the view's left and right edges. */
|
||||
ALAttributeVertical = ALAxisVertical,
|
||||
/** A horizontal line through the middle of the view's top and bottom edges. */
|
||||
ALAttributeHorizontal = ALAxisHorizontal,
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
|
||||
ALAttributeBaseline = ALAxisBaseline,
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */
|
||||
ALAttributeLastBaseline = ALAxisLastBaseline,
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
/** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */
|
||||
ALAttributeFirstBaseline = ALAxisFirstBaseline,
|
||||
/** The left margin of the view, based on the view's layoutMargins left inset. */
|
||||
ALAttributeMarginLeft = ALMarginLeft,
|
||||
/** The right margin of the view, based on the view's layoutMargins right inset. */
|
||||
ALAttributeMarginRight = ALMarginRight,
|
||||
/** The top margin of the view, based on the view's layoutMargins top inset. */
|
||||
ALAttributeMarginTop = ALMarginTop,
|
||||
/** The bottom margin of the view, based on the view's layoutMargins bottom inset. */
|
||||
ALAttributeMarginBottom = ALMarginBottom,
|
||||
/** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALAttributeMarginLeading = ALMarginLeading,
|
||||
/** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALAttributeMarginTrailing = ALMarginTrailing,
|
||||
/** A vertical line through the middle of the view's left and right margins. */
|
||||
ALAttributeMarginAxisVertical = ALMarginAxisVertical,
|
||||
/** A horizontal line through the middle of the view's top and bottom margins. */
|
||||
ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
};
|
||||
|
||||
/** A block containing method calls to the PureLayout API. Takes no arguments and has no return value. */
|
||||
typedef void(^ALConstraintsBlock)(void);
|
||||
|
||||
#endif /* PureLayoutDefines_h */
|
||||
Generated
+148
@@ -0,0 +1,148 @@
|
||||
# [](#)
|
||||
[](https://travis-ci.org/smileyborg/PureLayout) [](https://coveralls.io/r/smileyborg/PureLayout) [](http://cocoapods.org/?q=PureLayout) [](http://cocoapods.org/?q=PureLayout) [](LICENSE)
|
||||
|
||||
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends `UIView`/`NSView`, `NSArray`, and `NSLayoutConstraint` with a comprehensive Auto Layout API that is modeled after Apple's own frameworks. PureLayout is an Objective-C library that also works (and looks!) great with Swift using a bridging header.
|
||||
|
||||
Writing Auto Layout code from scratch isn't easy. PureLayout provides a fully capable and developer-friendly interface for Auto Layout. It is designed for clarity and simplicity, and takes inspiration from the AutoLayout UI options available in Interface Builder while delivering far more flexibility. The API is also highly efficient, as it adds only a thin layer of third party code and is engineered for maximum performance.
|
||||
|
||||
## API Cheat Sheet
|
||||
This is just a handy overview of the core API methods. Explore the [header files](PureLayout/PureLayout) for the full API, and find the complete documentation above the implementation of each method in the corresponding .m file. A couple of notes:
|
||||
|
||||
* All of the public API methods are namespaced with the prefix `auto...`, which also makes it easy for Xcode to autocomplete as you type.
|
||||
* Methods that create constraints also automatically install (activate) the constraint(s), then return the new constraint(s) for you to optionally store for later adjustment or removal.
|
||||
* Many methods below also have a variant which includes a `relation:` parameter to make the constraint an inequality.
|
||||
|
||||
### Attributes
|
||||
|
||||
PureLayout defines view attributes that are used to create auto layout constraints. Here is an [illustration of the most common attributes](Images/PureLayout-CommonAttributes.png).
|
||||
|
||||
There are 5 specific attribute types, which are used throughout most of the API:
|
||||
|
||||
* `ALEdge`
|
||||
* `ALDimension`
|
||||
* `ALAxis`
|
||||
* `ALMargin` *available in iOS 8.0 and higher only*
|
||||
* `ALMarginAxis` *available in iOS 8.0 and higher only*
|
||||
|
||||
Additionally, there is one generic attribute type, `ALAttribute`, which is effectively a union of all the specific types. You can think of this as the "supertype" of all of the specific attribute types, which means that it is always safe to cast a specific type to the generic `ALAttribute` type. (Note that the reverse is not true -- casting a generic ALAttribute to a specific attribute type is unsafe!)
|
||||
|
||||
### [`UIView`/`NSView`](PureLayout/PureLayout/ALView%2BPureLayout.h)
|
||||
|
||||
+ autoCreateConstraintsWithoutInstalling:
|
||||
+ autoSetPriority:forConstraints:
|
||||
+ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only
|
||||
- autoSetContent(CompressionResistance|Hugging)PriorityForAxis:
|
||||
- autoCenterInSuperview:
|
||||
- autoAlignAxisToSuperviewAxis:
|
||||
- autoCenterInSuperviewMargins: // iOS 8.0+ only
|
||||
- autoAlignAxisToSuperviewMarginAxis: // iOS 8.0+ only
|
||||
- autoPinEdgeToSuperviewEdge:(withInset:)
|
||||
- autoPinEdgesToSuperviewEdgesWithInsets:(excludingEdge:)
|
||||
- autoPinEdgeToSuperviewMargin: // iOS 8.0+ only
|
||||
- autoPinEdgesToSuperviewMargins(ExcludingEdge:) // iOS 8.0+ only
|
||||
- autoPinEdge:toEdge:ofView:(withOffset:)
|
||||
- autoAlignAxis:toSameAxisOfView:(withOffset:)
|
||||
- autoMatchDimension:toDimension:ofView:(withOffset:|withMultiplier:)
|
||||
- autoSetDimension(s)ToSize:
|
||||
- autoConstrainAttribute:toAttribute:ofView:(withOffset:|withMultiplier:)
|
||||
- autoPinTo(Top|Bottom)LayoutGuideOfViewController:withInset: // iOS only
|
||||
|
||||
### [`NSArray`](PureLayout/PureLayout/NSArray%2BPureLayout.h)
|
||||
|
||||
// Arrays of Constraints
|
||||
- autoInstallConstraints
|
||||
- autoRemoveConstraints
|
||||
- autoIdentifyConstraints: // iOS 7.0+, OS X 10.9+ only
|
||||
|
||||
// Arrays of Views
|
||||
- autoAlignViewsToEdge:
|
||||
- autoAlignViewsToAxis:
|
||||
- autoMatchViewsDimension:
|
||||
- autoSetViewsDimension:toSize:
|
||||
- autoSetViewsDimensionsToSize:
|
||||
- autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:)
|
||||
- autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:)
|
||||
|
||||
### [`NSLayoutConstraint`](PureLayout/PureLayout/NSLayoutConstraint%2BPureLayout.h)
|
||||
|
||||
- autoInstall
|
||||
- autoRemove
|
||||
- autoIdentify: // iOS 7.0+, OS X 10.9+ only
|
||||
|
||||
## Setup
|
||||
*Note: PureLayout requires a minimum deployment target of iOS 6.0 or OS X 10.7*
|
||||
|
||||
### Using [CocoaPods](http://cocoapods.org)
|
||||
1. Add the pod `PureLayout` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html).
|
||||
|
||||
pod 'PureLayout'
|
||||
|
||||
2. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode.
|
||||
3. Import the `PureLayout.h` header. Typically, this should be written as `#import <PureLayout/PureLayout.h>`
|
||||
|
||||
That's it - now go write some beautiful Auto Layout code!
|
||||
|
||||
### Using [Carthage](https://github.com/Carthage/Carthage)
|
||||
1. Add the `smileyborg/PureLayout` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile).
|
||||
|
||||
github "smileyborg/PureLayout"
|
||||
|
||||
2. Run `carthage update`, then follow the [additional steps required](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add the iOS and/or Mac frameworks into your project.
|
||||
3. Import the PureLayout framework/module (with the appropriate name for the platform you're using it on).
|
||||
* Using Modules: `@import PureLayout_iOS` or `@import PureLayout_Mac`
|
||||
* Without Modules: `#import <PureLayout_iOS/PureLayout_iOS.h>` or `#import <PureLayout_Mac/PureLayout_Mac.h>`
|
||||
|
||||
That's it - now go write some beautiful Auto Layout code!
|
||||
|
||||
### Manually from GitHub
|
||||
1. Download the source files in the [PureLayout subdirectory](PureLayout/PureLayout).
|
||||
2. Add the source files to your Xcode project.
|
||||
3. Import the `PureLayout.h` header.
|
||||
|
||||
That's it - now go write some beautiful Auto Layout code!
|
||||
|
||||
### App Extensions
|
||||
To use PureLayout in an App Extension, you need to do a bit of extra configuration to prevent usage of unavailable APIs. [Click here](https://github.com/smileyborg/PureLayout/wiki/App-Extensions) for more info.
|
||||
|
||||
### Releases
|
||||
Releases are tagged in the git commit history using [semantic versioning](http://semver.org). Check out the [releases and release notes](https://github.com/smileyborg/PureLayout/releases) for each version.
|
||||
|
||||
## Usage
|
||||
### Example Project
|
||||
Open the project included in the repository (requires Xcode 6 or higher). It contains [iOS](PureLayout/Example-iOS) (`Example-iOS` scheme) and [OS X](PureLayout/Example-Mac) (`Example-Mac` scheme) demos of the library being used in various scenarios.
|
||||
|
||||
On iOS, you can use different device simulators and rotate the device to see the constraints in action (as well as toggle the taller in-call status bar in the iOS Simulator).
|
||||
|
||||
On OS X, while running the app, press any key to cycle through the demos. You can resize the window to see the constraints in action.
|
||||
|
||||
### Tips and Tricks
|
||||
Check out some [Tips and Tricks](https://github.com/smileyborg/PureLayout/wiki/Tips-and-Tricks) to keep in mind when using the API.
|
||||
|
||||
## PureLayout vs. the rest
|
||||
An overview of the Auto Layout options available, ordered from the lowest- to highest-level of abstraction.
|
||||
|
||||
* Apple [NSLayoutConstraint SDK API](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:)
|
||||
* Pros: Raw power
|
||||
* Cons: Extremely verbose, tedious to write, difficult to read
|
||||
* Apple [Visual Format Language](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html)
|
||||
* Pros: Concise, convenient
|
||||
* Cons: Doesn't support some use cases, incomplete compile-time checks, must learn syntax, hard to debug
|
||||
* Apple Interface Builder
|
||||
* Pros: Visual, simple
|
||||
* Cons: Difficult for complex layouts, cannot dynamically set constraints at runtime, encourages hardcoded magic numbers, not always WYSIWYG
|
||||
* **PureLayout**
|
||||
* Pros: Simple, efficient, minimal third party code, consistent with Cocoa API style, compatible with Objective-C and Swift codebases
|
||||
* Cons: Not the most concise expression of layout code
|
||||
* High-level Auto Layout Libraries/DSLs ([Cartography](https://github.com/robb/Cartography), [SnapKit](https://github.com/SnapKit/SnapKit), [KeepLayout](https://github.com/iMartinKiss/KeepLayout))
|
||||
* Pros: Very clean, concise, and convenient
|
||||
* Cons: Unique API style is foreign to Cocoa APIs, mixed compatibility with Objective-C & Swift, greater dependency on third party code
|
||||
|
||||
PureLayout takes a balanced approach to Auto Layout that makes it well suited for any project.
|
||||
|
||||
## Problems, Suggestions, Pull Requests?
|
||||
Please open a [new Issue here](https://github.com/smileyborg/PureLayout/issues/new) if you run into an issue, have a feature request, or want to share a comment. Note that general Auto Layout questions should be asked on [Stack Overflow](http://stackoverflow.com).
|
||||
|
||||
If you're considering taking on significant changes or additions to the project, please communicate in advance by opening a new Issue. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work.
|
||||
|
||||
## Meta
|
||||
Designed & maintained by Tyler Fox ([@smileyborg](https://twitter.com/smileyborg)). Distributed with the MIT license.
|
||||
Reference in new issue
Block a user