- Fix present picker controller
This commit is contained in:
1 parent
2aa49f6ad1
commit
5974642e25
277 files changed
+14514
-11692
No files matched your search
+43
-14
@@ -29,7 +29,7 @@
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
PL__ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark ALView+PureLayout
|
||||
|
||||
@@ -54,21 +54,44 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
#pragma mark Center & Align in Superview
|
||||
|
||||
/** Centers the view in its superview. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview;
|
||||
|
||||
/** Aligns the view to the same axis of its superview. */
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Centers the view in its superview's margins. Available in iOS 8.0 and later. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)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 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
#pragma mark Pin Edges to SafeArea
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview anchor/edge. */
|
||||
- (NSLayoutConstraint *)API_AVAILABLE(ios(9.0), tvos(9.0))autoPinEdgeToSuperviewSafeArea:(ALEdge)edge;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview anchor/edge with an inset. */
|
||||
- (NSLayoutConstraint *)API_AVAILABLE(ios(9.0), tvos(9.0))autoPinEdgeToSuperviewSafeArea:(ALEdge)edge withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview anchor/edge with an inset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)API_AVAILABLE(ios(9.0), tvos(9.0))autoPinEdgeToSuperviewSafeArea:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview anchors/edge. */
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)API_AVAILABLE(ios(9.0), tvos(9.0))autoPinEdgesToSuperviewSafeArea;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview anchors/edges with the given edge insets. */
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)API_AVAILABLE(ios(9.0), tvos(9.0))autoPinEdgesToSuperviewSafeAreaWithInsets:(ALEdgeInsets)insets;
|
||||
|
||||
/** Pins 3 of the 4 edges of the view to the edges of its superview anchor/edge with the given edge insets, excluding one edge. */
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)API_AVAILABLE(ios(9.0), tvos(9.0))autoPinEdgesToSuperviewSafeAreaWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
#pragma mark Pin Edges to Superview
|
||||
|
||||
@@ -82,29 +105,35 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview with the given edge insets. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)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_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__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 a view to the corresponding margin of its superview with an inset.*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge withInset:(CGFloat)inset;
|
||||
|
||||
/** 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_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins;
|
||||
|
||||
/** Pins the edges of the view to the margins of its superview with the given edge insets. Available in iOS 8.0 and later.*/
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsWithInsets:(ALEdgeInsets)insets;
|
||||
|
||||
/** 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_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges
|
||||
@@ -152,7 +181,7 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
#pragma mark Set Dimensions
|
||||
|
||||
/** Sets the view to a specific size. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size;
|
||||
|
||||
/** Sets the given dimension of the view to a specific size. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
@@ -210,4 +239,4 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
PL__ASSUME_NONNULL_END
|
||||
+358
-60
@@ -78,9 +78,9 @@
|
||||
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]];
|
||||
return constraints;
|
||||
@@ -100,16 +100,16 @@
|
||||
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:superview];
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Centers the view in its superview, taking into account the layout margins of both the view and its superview.
|
||||
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]];
|
||||
return constraints;
|
||||
@@ -130,9 +130,237 @@
|
||||
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)marginAxis ofView:superview];
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges to SafeArea
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the same edge of its superview anchor.
|
||||
|
||||
@param edge The edge of this view and its superview to pin.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewSafeArea:(ALEdge)edge
|
||||
{
|
||||
return [self autoPinEdgeToSuperviewSafeArea:edge withInset:0.0];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the same edge of its superview anchor with an inset.
|
||||
|
||||
@param edge The edge of this view and its superview to pin.
|
||||
@param inset The amount to inset this view's edge from the superview's edge.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewSafeArea:(ALEdge)edge withInset:(CGFloat)inset
|
||||
{
|
||||
return [self autoPinEdgeToSuperviewSafeArea:edge withInset:inset relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the same edge of its superview anchor/edge with an inset as a maximum or minimum.
|
||||
|
||||
@param edge The edge of this view and its superview to pin.
|
||||
@param inset The amount to inset this view's edge from the superview's edge.
|
||||
@param relation Whether the inset should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewSafeArea:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_9_0
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
ALView *superview = self.superview;
|
||||
NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
|
||||
NSLayoutConstraint *constraint = nil;
|
||||
NSLayoutYAxisAnchor *topAnchor;
|
||||
NSLayoutYAxisAnchor *bottomAnchor;
|
||||
NSLayoutXAxisAnchor *leftAnchor;
|
||||
NSLayoutXAxisAnchor *rightAnchor;
|
||||
NSLayoutXAxisAnchor *leadingAnchor;
|
||||
NSLayoutXAxisAnchor *trailingAnchor;
|
||||
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_11_0 // only iOS/tvOS SDK 11.0 has @available syntax introduced
|
||||
if (@available(iOS 11.0, tvOS 11.0, *)) {
|
||||
topAnchor = superview.safeAreaLayoutGuide.topAnchor;
|
||||
bottomAnchor = superview.safeAreaLayoutGuide.bottomAnchor;
|
||||
leftAnchor = superview.safeAreaLayoutGuide.leftAnchor;
|
||||
rightAnchor = superview.safeAreaLayoutGuide.rightAnchor;
|
||||
leadingAnchor = superview.safeAreaLayoutGuide.leadingAnchor;
|
||||
trailingAnchor = superview.safeAreaLayoutGuide.trailingAnchor;
|
||||
} else if (@available(iOS 9.0, *)) {
|
||||
topAnchor = superview.topAnchor;
|
||||
bottomAnchor = superview.bottomAnchor;
|
||||
leftAnchor = superview.leftAnchor;
|
||||
rightAnchor = superview.rightAnchor;
|
||||
leadingAnchor = superview.leadingAnchor;
|
||||
trailingAnchor = superview.trailingAnchor;
|
||||
} else { // for targeting iOS 8 or below without anchor system
|
||||
return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:relation];
|
||||
}
|
||||
#elif PL__PureLayout_MinBaseSDK_iOS_9_0 // fallback to older SDKs, when using Xcode 8.0, which only has iOS SDK 10.0
|
||||
if (PL__PureLayout_MinSysVer_iOS_9_0) {
|
||||
topAnchor = superview.topAnchor;
|
||||
bottomAnchor = superview.bottomAnchor;
|
||||
leftAnchor = superview.leftAnchor;
|
||||
rightAnchor = superview.rightAnchor;
|
||||
leadingAnchor = superview.leadingAnchor;
|
||||
trailingAnchor = superview.trailingAnchor;
|
||||
} else { // for targeting iOS 8 or below without anchor system
|
||||
return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:relation];
|
||||
}
|
||||
#endif
|
||||
if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) {
|
||||
// The bottom, right, and trailing insets (and relations, if an inequality) are inverted to become offsets
|
||||
inset = -inset;
|
||||
}
|
||||
switch (edge) {
|
||||
case ALEdgeLeft:
|
||||
switch (relation) {
|
||||
case NSLayoutRelationEqual:
|
||||
constraint = [[self leftAnchor] constraintEqualToAnchor:leftAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationLessThanOrEqual:
|
||||
constraint = [[self leftAnchor] constraintLessThanOrEqualToAnchor:leftAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationGreaterThanOrEqual:
|
||||
constraint = [[self leftAnchor] constraintGreaterThanOrEqualToAnchor:leftAnchor constant:inset];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ALEdgeRight:
|
||||
switch (relation) {
|
||||
case NSLayoutRelationEqual:
|
||||
constraint = [[self rightAnchor] constraintEqualToAnchor:rightAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationLessThanOrEqual:
|
||||
constraint = [[self rightAnchor] constraintGreaterThanOrEqualToAnchor:rightAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationGreaterThanOrEqual:
|
||||
constraint = [[self rightAnchor] constraintLessThanOrEqualToAnchor:rightAnchor constant:inset];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ALEdgeTop:
|
||||
switch (relation) {
|
||||
case NSLayoutRelationEqual:
|
||||
constraint = [[self topAnchor] constraintEqualToAnchor:topAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationLessThanOrEqual:
|
||||
constraint = [[self topAnchor] constraintLessThanOrEqualToAnchor:topAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationGreaterThanOrEqual:
|
||||
constraint = [[self topAnchor] constraintGreaterThanOrEqualToAnchor:topAnchor constant:inset];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ALEdgeBottom:
|
||||
switch (relation) {
|
||||
case NSLayoutRelationEqual:
|
||||
constraint = [[self bottomAnchor] constraintEqualToAnchor:bottomAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationLessThanOrEqual:
|
||||
constraint = [[self bottomAnchor] constraintGreaterThanOrEqualToAnchor:bottomAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationGreaterThanOrEqual:
|
||||
constraint = [[self bottomAnchor] constraintLessThanOrEqualToAnchor:bottomAnchor constant:inset];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ALEdgeLeading:
|
||||
switch (relation) {
|
||||
case NSLayoutRelationEqual:
|
||||
constraint = [[self leadingAnchor] constraintEqualToAnchor:leadingAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationLessThanOrEqual:
|
||||
constraint = [[self leadingAnchor] constraintLessThanOrEqualToAnchor:leadingAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationGreaterThanOrEqual:
|
||||
constraint = [[self leadingAnchor] constraintGreaterThanOrEqualToAnchor:leadingAnchor constant:inset];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ALEdgeTrailing:
|
||||
switch (relation) {
|
||||
case NSLayoutRelationEqual:
|
||||
constraint = [[self trailingAnchor] constraintEqualToAnchor:trailingAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationLessThanOrEqual:
|
||||
constraint = [[self trailingAnchor] constraintGreaterThanOrEqualToAnchor:trailingAnchor constant:inset];
|
||||
break;
|
||||
case NSLayoutRelationGreaterThanOrEqual:
|
||||
constraint = [[self trailingAnchor] constraintLessThanOrEqualToAnchor:trailingAnchor constant:inset];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
constraint.active = YES;
|
||||
return constraint;
|
||||
#else
|
||||
return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:relation];
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_9_0 */
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the edges of the view to the edges of its superview anchor.
|
||||
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewSafeArea
|
||||
{
|
||||
return [self autoPinEdgesToSuperviewSafeAreaWithInsets:ALEdgeInsetsZero];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the edges of the view to the edges of its superview anchor with the given edge insets.
|
||||
The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
|
||||
|
||||
@param insets The insets for this view's edges from its superview's edges.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewSafeAreaWithInsets:(ALEdgeInsets)insets
|
||||
{
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeLeading withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeBottom withInset:insets.bottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeTrailing withInset:insets.right]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Pins 3 of the 4 edges of the view to the edges of its superview anchor with the given edge insets, excluding one edge.
|
||||
The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
|
||||
|
||||
@param insets The insets for this view's edges from its superview's edges. The inset corresponding to the excluded edge
|
||||
will be ignored.
|
||||
@param edge The edge of this view to exclude in pinning to its superview anchor; this method will not apply any constraint to it.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewSafeAreaWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge
|
||||
{
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
|
||||
if (edge != ALEdgeTop) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeTop withInset:insets.top]];
|
||||
}
|
||||
if (edge != ALEdgeLeading && edge != ALEdgeLeft) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeLeading withInset:insets.left]];
|
||||
}
|
||||
if (edge != ALEdgeBottom) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeBottom withInset:insets.bottom]];
|
||||
}
|
||||
if (edge != ALEdgeTrailing && edge != ALEdgeRight) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewSafeArea:ALEdgeTrailing withInset:insets.right]];
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
#pragma mark Pin Edges to Superview
|
||||
|
||||
/**
|
||||
@@ -186,9 +414,9 @@
|
||||
/**
|
||||
Pins the edges of the view to the edges of its superview.
|
||||
|
||||
@return An array of constraints added.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges
|
||||
{
|
||||
return [self autoPinEdgesToSuperviewEdgesWithInsets:ALEdgeInsetsZero];
|
||||
}
|
||||
@@ -198,11 +426,11 @@
|
||||
The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
|
||||
|
||||
@param insets The insets for this view's edges from its superview's edges.
|
||||
@return An array of constraints added.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
@@ -217,27 +445,47 @@
|
||||
@param insets The insets for this view's edges from its superview's edges. The inset corresponding to the excluded edge
|
||||
will be ignored.
|
||||
@param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it.
|
||||
@return An array of constraints added.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
if (edge != ALEdgeTop) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
}
|
||||
if (edge != ALEdgeLeading && edge != ALEdgeLeft) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
|
||||
}
|
||||
if (edge != ALEdgeBottom) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
}
|
||||
if (edge != ALEdgeTrailing && edge != ALEdgeRight) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
switch (edge) {
|
||||
case ALEdgeLeft:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:insets.right]];
|
||||
break;
|
||||
case ALEdgeRight:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
break;
|
||||
case ALEdgeTop:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
|
||||
break;
|
||||
case ALEdgeBottom:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
|
||||
break;
|
||||
case ALEdgeLeading:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
|
||||
break;
|
||||
case ALEdgeTrailing:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
break;
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the corresponding margin of its superview.
|
||||
@@ -250,6 +498,26 @@
|
||||
return [self autoPinEdgeToSuperviewMargin:edge relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the corresponding margin of its superview with an inset.
|
||||
|
||||
@param edge The edge of this view to pin to the corresponding margin of its superview.
|
||||
@param @param inset The amount to inset this view's edge from the corresponding margin of its superview edge.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge withInset:(CGFloat)inset
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALView *superview = self.superview;
|
||||
NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
|
||||
if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) {
|
||||
// The bottom, right, and trailing insets (and relations, if an inequality) are inverted to become offsets
|
||||
inset = -inset;
|
||||
}
|
||||
ALMargin margin = [NSLayoutConstraint al_marginForEdge:edge];
|
||||
return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)margin ofView:superview withOffset:inset];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum.
|
||||
|
||||
@@ -273,19 +541,31 @@
|
||||
ALMargin margin = [NSLayoutConstraint al_marginForEdge:edge];
|
||||
return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)margin ofView:superview withOffset:0.0 relation:relation];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Pins the edges of the view to the margins of its superview.
|
||||
|
||||
@return An array of constraints added.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]];
|
||||
return [self autoPinEdgesToSuperviewMarginsWithInsets:ALEdgeInsetsZero];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the edges of the view to the edges of its corresponding margins of its superview with the given edge insets.
|
||||
The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
|
||||
|
||||
@param insets The insets for this view's edges from its corresponding margin of its superview.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsWithInsets:(ALEdgeInsets)insets
|
||||
{
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom withInset:insets.bottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing withInset:insets.right]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
@@ -293,27 +573,47 @@
|
||||
Pins 3 of the 4 edges of the view to the margins of its superview, excluding one edge.
|
||||
|
||||
@param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it.
|
||||
@return An array of constraints added.
|
||||
@return An array of constraints added, ordered counterclockwise from top.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
if (edge != ALEdgeTop) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
}
|
||||
if (edge != ALEdgeLeading && edge != ALEdgeLeft) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
|
||||
}
|
||||
if (edge != ALEdgeBottom) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
}
|
||||
if (edge != ALEdgeTrailing && edge != ALEdgeRight) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
switch (edge) {
|
||||
case ALEdgeLeft:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeRight]];
|
||||
break;
|
||||
case ALEdgeRight:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeft]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
break;
|
||||
case ALEdgeTop:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]];
|
||||
break;
|
||||
case ALEdgeBottom:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]];
|
||||
break;
|
||||
case ALEdgeLeading:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]];
|
||||
break;
|
||||
case ALEdgeTrailing:
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
break;
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges
|
||||
@@ -360,7 +660,6 @@
|
||||
return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)toEdge ofView:otherView withOffset:offset relation:relation];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Align Axes
|
||||
|
||||
/**
|
||||
@@ -484,9 +783,9 @@
|
||||
@param size The size to set this view's dimensions to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]];
|
||||
[constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]];
|
||||
return constraints;
|
||||
@@ -674,7 +973,7 @@
|
||||
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
if (__PureLayout_MinSysVer_iOS_7_0) {
|
||||
if (PL__PureLayout_MinSysVer_iOS_7_0) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:relation toItem:viewController.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:inset];
|
||||
[viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view
|
||||
@@ -708,7 +1007,7 @@
|
||||
} else if (relation == NSLayoutRelationGreaterThanOrEqual) {
|
||||
relation = NSLayoutRelationLessThanOrEqual;
|
||||
}
|
||||
if (__PureLayout_MinSysVer_iOS_7_0) {
|
||||
if (PL__PureLayout_MinSysVer_iOS_7_0) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:relation toItem:viewController.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:inset];
|
||||
[viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view
|
||||
@@ -721,7 +1020,6 @@
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
|
||||
#pragma mark Internal Methods
|
||||
|
||||
/**
|
||||
@@ -793,13 +1091,13 @@
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBaseline.");
|
||||
constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:otherView];
|
||||
break;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAttributeFirstBaseline:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAttributeFirstBaseline is only supported on iOS 8.0 or higher.");
|
||||
NSAssert(PL__PureLayout_MinSysVer_iOS_8_0, @"ALAttributeFirstBaseline is only supported on iOS 8.0 or higher.");
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeFirstBaseline.");
|
||||
constraint = [self autoAlignAxis:ALAxisFirstBaseline toSameAxisOfView:otherView];
|
||||
break;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
case ALAttributeTop:
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeTop.");
|
||||
constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:otherView];
|
||||
@@ -828,7 +1126,7 @@
|
||||
// All of the below attributes are invalid as alignment options. Listing them explicitly (even though they just fall through to the default case) to avoid an incomplete switch statement warning from the compiler.
|
||||
case ALAttributeWidth:
|
||||
case ALAttributeHeight:
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAttributeMarginLeft:
|
||||
case ALAttributeMarginRight:
|
||||
case ALAttributeMarginTop:
|
||||
@@ -837,7 +1135,7 @@
|
||||
case ALAttributeMarginTrailing:
|
||||
case ALAttributeMarginAxisVertical:
|
||||
case ALAttributeMarginAxisHorizontal:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
default:
|
||||
NSAssert(nil, @"Unsupported attribute for alignment.");
|
||||
break;
|
||||
|
||||
+14
-14
@@ -29,7 +29,7 @@
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
PL__ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark NSArray+PureLayout
|
||||
|
||||
@@ -49,48 +49,48 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
/** Deactivates the constraints in this array. */
|
||||
- (void)autoRemoveConstraints;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/** 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 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Array of Views
|
||||
|
||||
/** Aligns views in this array to one another along a given edge. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge;
|
||||
|
||||
/** Aligns views in this array to one another along a given axis. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis;
|
||||
|
||||
/** Matches a given dimension of all the views in this array. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension;
|
||||
|
||||
/** Sets the given dimension of all the views in this array to a given size. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
|
||||
/** Sets all of the views in this array to a given size. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size;
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)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_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)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_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)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_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
@@ -99,17 +99,17 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/** 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_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)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_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
insetSpacing:(BOOL)shouldSpaceInsets;
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
PL__ASSUME_NONNULL_END
|
||||
+30
-30
@@ -44,7 +44,7 @@
|
||||
*/
|
||||
- (void)autoInstallConstraints
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) {
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
@@ -58,7 +58,7 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
@@ -72,12 +72,12 @@
|
||||
*/
|
||||
- (void)autoRemoveConstraints
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__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 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
@@ -86,7 +86,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/**
|
||||
Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later.
|
||||
@@ -106,7 +106,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Array of Views
|
||||
@@ -118,10 +118,10 @@
|
||||
@param edge The edge to which the views will be aligned.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@@ -143,10 +143,10 @@
|
||||
@param axis The axis to which the views will be aligned.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@@ -168,10 +168,10 @@
|
||||
@param dimension The dimension to match for all of the views.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@@ -194,10 +194,10 @@
|
||||
@param size The size to set the given dimension of each view to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
@@ -215,9 +215,9 @@
|
||||
@param size The size to set each view's dimensions to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]];
|
||||
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]];
|
||||
return constraints;
|
||||
@@ -234,7 +234,7 @@
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
{
|
||||
@@ -255,7 +255,7 @@
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
@@ -280,7 +280,7 @@
|
||||
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_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
@@ -292,9 +292,9 @@
|
||||
switch (axis) {
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
matchedDimension = ALDimensionWidth;
|
||||
firstEdge = ALEdgeLeading;
|
||||
lastEdge = ALEdgeTrailing;
|
||||
@@ -311,7 +311,7 @@
|
||||
CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@@ -349,7 +349,7 @@
|
||||
@param size The fixed size of each view in the dimension along the given axis.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
{
|
||||
@@ -370,7 +370,7 @@
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
@@ -381,9 +381,9 @@
|
||||
switch (axis) {
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
fixedDimension = ALDimensionWidth;
|
||||
attribute = NSLayoutAttributeCenterX;
|
||||
break;
|
||||
@@ -407,8 +407,8 @@
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally
|
||||
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
__NSArray_of(ALView *) *views = [self al_copyViewsOnly];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSArray_of(ALView *) *views = [self al_copyViewsOnly];
|
||||
NSUInteger numberOfViews = [views count];
|
||||
ALView *commonSuperview = [views al_commonSuperviewOfViews];
|
||||
ALView *previousView = nil;
|
||||
@@ -491,9 +491,9 @@
|
||||
|
||||
@return A new array containing only the views that are in this array.
|
||||
*/
|
||||
- (__NSArray_of(ALView *) *)al_copyViewsOnly
|
||||
- (PL__NSArray_of(ALView *) *)al_copyViewsOnly
|
||||
{
|
||||
__NSMutableArray_of(ALView *) *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]];
|
||||
PL__NSMutableArray_of(ALView *) *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]];
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
[viewsOnlyArray addObject:object];
|
||||
|
||||
+8
-8
@@ -28,7 +28,7 @@
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
PL__ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark NSLayoutConstraint+PureLayout
|
||||
|
||||
@@ -43,32 +43,32 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
/** Creates all of the constraints in the block, then installs (activates) them all at once.
|
||||
All constraints created from calls to the PureLayout API in the block are returned in a single array.
|
||||
This may be more efficient than installing (activating) each constraint one-by-one. */
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block;
|
||||
+ (PL__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(__attribute__((noescape)) ALConstraintsBlock)block;
|
||||
|
||||
/** Creates all of the constraints in the block but prevents them from being automatically installed (activated).
|
||||
All constraints created from calls to the PureLayout API in the block are returned in a single array. */
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block;
|
||||
+ (PL__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(__attribute__((noescape)) 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;
|
||||
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(__attribute__((noescape)) ALConstraintsBlock)block;
|
||||
|
||||
|
||||
#pragma mark Identify Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/** 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;
|
||||
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(__attribute__((noescape)) ALConstraintsBlock)block;
|
||||
|
||||
/** 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 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Install & Remove Constraints
|
||||
@@ -81,4 +81,4 @@ __PL_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
PL__ASSUME_NONNULL_END
|
||||
+38
-38
@@ -46,7 +46,7 @@
|
||||
|
||||
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
|
||||
*/
|
||||
static __NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *_al_arraysOfCreatedConstraints = nil;
|
||||
static PL__NSMutableArray_of(PL__NSMutableArray_of(NSLayoutConstraint *) *) *_al_arraysOfCreatedConstraints = nil;
|
||||
|
||||
/**
|
||||
A global variable that is set to YES when installing a batch of constraints collected from a call to +[autoCreateAndInstallConstraints].
|
||||
@@ -59,7 +59,7 @@ static BOOL _al_isInstallingCreatedConstraints = NO;
|
||||
/**
|
||||
Accessor for the global state that stores arrays of constraints created without being installed.
|
||||
*/
|
||||
+ (__NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *)al_arraysOfCreatedConstraints
|
||||
+ (PL__NSMutableArray_of(PL__NSMutableArray_of(NSLayoutConstraint *) *) *)al_arraysOfCreatedConstraints
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
|
||||
if (!_al_arraysOfCreatedConstraints) {
|
||||
@@ -71,7 +71,7 @@ static BOOL _al_isInstallingCreatedConstraints = NO;
|
||||
/**
|
||||
Accessor for the current mutable array of constraints created without being immediately installed.
|
||||
*/
|
||||
+ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints
|
||||
+ (PL__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints
|
||||
{
|
||||
return [[self al_arraysOfCreatedConstraints] lastObject];
|
||||
}
|
||||
@@ -95,7 +95,7 @@ static BOOL _al_isInstallingCreatedConstraints = NO;
|
||||
@param block A block of method calls to the PureLayout API that create constraints.
|
||||
@return An array of the constraints that were created from calls to the PureLayout API inside the block.
|
||||
*/
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block
|
||||
+ (PL__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(__attribute__((noescape)) ALConstraintsBlock)block
|
||||
{
|
||||
NSArray *createdConstraints = [self autoCreateConstraintsWithoutInstalling:block];
|
||||
_al_isInstallingCreatedConstraints = YES;
|
||||
@@ -114,7 +114,7 @@ static BOOL _al_isInstallingCreatedConstraints = NO;
|
||||
@param block A block of method calls to the PureLayout API that create constraints.
|
||||
@return An array of the constraints that were created from calls to the PureLayout API inside the block.
|
||||
*/
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block
|
||||
+ (PL__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(__attribute__((noescape)) ALConstraintsBlock)block
|
||||
{
|
||||
NSAssert(block, @"The constraints block cannot be nil.");
|
||||
NSArray *createdConstraints = nil;
|
||||
@@ -138,12 +138,12 @@ static BOOL _al_isInstallingCreatedConstraints = NO;
|
||||
constraints created by this library (even if automatic constraint installation is being prevented).
|
||||
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
|
||||
*/
|
||||
static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
|
||||
static PL__NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
|
||||
|
||||
/**
|
||||
Accessor for the global stack of layout priorities.
|
||||
*/
|
||||
+ (__NSMutableArray_of(NSNumber *) *)al_globalConstraintPriorities
|
||||
+ (PL__NSMutableArray_of(NSNumber *) *)al_globalConstraintPriorities
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
|
||||
if (!_al_globalConstraintPriorities) {
|
||||
@@ -159,7 +159,7 @@ static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
|
||||
*/
|
||||
+ (ALLayoutPriority)al_currentGlobalConstraintPriority
|
||||
{
|
||||
__NSMutableArray_of(NSNumber *) *globalConstraintPriorities = [self al_globalConstraintPriorities];
|
||||
PL__NSMutableArray_of(NSNumber *) *globalConstraintPriorities = [self al_globalConstraintPriorities];
|
||||
if ([globalConstraintPriorities count] == 0) {
|
||||
return ALLayoutPriorityRequired;
|
||||
}
|
||||
@@ -184,7 +184,7 @@ static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
|
||||
@param priority The layout priority to be set on all constraints created in the constraints block.
|
||||
@param block A block of method calls to the PureLayout API that create and install constraints.
|
||||
*/
|
||||
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block
|
||||
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(__attribute__((noescape)) ALConstraintsBlock)block
|
||||
{
|
||||
NSAssert(block, @"The constraints block cannot be nil.");
|
||||
if (block) {
|
||||
@@ -197,7 +197,7 @@ static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
|
||||
|
||||
#pragma mark Identify Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/**
|
||||
A global variable that stores a stack of identifier strings to set on constraints.
|
||||
@@ -207,12 +207,12 @@ static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
|
||||
constraints created by this library (even if automatic constraint installation is being prevented).
|
||||
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
|
||||
*/
|
||||
static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
static PL__NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
|
||||
/**
|
||||
Accessor for the global state of constraint identifiers.
|
||||
*/
|
||||
+ (__NSMutableArray_of(NSString *) *)al_globalConstraintIdentifiers
|
||||
+ (PL__NSMutableArray_of(NSString *) *)al_globalConstraintIdentifiers
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
|
||||
if (!_al_globalConstraintIdentifiers) {
|
||||
@@ -228,7 +228,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
*/
|
||||
+ (NSString *)al_currentGlobalConstraintIdentifier
|
||||
{
|
||||
__NSMutableArray_of(NSString *) *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers];
|
||||
PL__NSMutableArray_of(NSString *) *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers];
|
||||
if ([globalConstraintIdentifiers count] == 0) {
|
||||
return nil;
|
||||
}
|
||||
@@ -244,7 +244,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
@param identifier A string used to identify all constraints created in the constraints block.
|
||||
@param block A block of method calls to the PureLayout API that create and install constraints.
|
||||
*/
|
||||
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block
|
||||
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(__attribute__((noescape)) ALConstraintsBlock)block
|
||||
{
|
||||
NSAssert(block, @"The constraints block cannot be nil.");
|
||||
NSAssert(identifier, @"The identifier string cannot be nil.");
|
||||
@@ -275,7 +275,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Install & Remove Constraints
|
||||
@@ -285,7 +285,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
*/
|
||||
- (void)autoInstall
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([self respondsToSelector:@selector(setActive:)]) {
|
||||
[NSLayoutConstraint al_applyGlobalStateToConstraint:self];
|
||||
if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
|
||||
@@ -295,7 +295,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem.");
|
||||
if (self.firstItem) {
|
||||
@@ -318,12 +318,12 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
*/
|
||||
- (void)autoRemove
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__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 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
if (self.secondItem) {
|
||||
ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem];
|
||||
@@ -356,12 +356,12 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
|
||||
constraint.priority = [NSLayoutConstraint al_currentGlobalConstraintPriority];
|
||||
}
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
NSString *globalConstraintIdentifier = [NSLayoutConstraint al_currentGlobalConstraintIdentifier];
|
||||
if (globalConstraintIdentifier) {
|
||||
[constraint autoIdentify:globalConstraintIdentifier];
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,44 +406,44 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
layoutAttribute = NSLayoutAttributeBaseline;
|
||||
break;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisFirstBaseline is only supported on iOS 8.0 or higher.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__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.");
|
||||
NSAssert(PL__PureLayout_MinSysVer_iOS_8_0, @"ALAxisHorizontalMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeCenterYWithinMargins;
|
||||
break;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAttribute.");
|
||||
break;
|
||||
@@ -465,9 +465,9 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
break;
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
constraintAxis = ALLayoutConstraintAxisHorizontal;
|
||||
break;
|
||||
default:
|
||||
@@ -478,7 +478,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
return constraintAxis;
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Returns the corresponding margin for the given edge.
|
||||
@@ -488,7 +488,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
*/
|
||||
+ (ALMargin)al_marginForEdge:(ALEdge)edge
|
||||
{
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
NSAssert(PL__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
ALMargin margin;
|
||||
switch (edge) {
|
||||
case ALEdgeLeft:
|
||||
@@ -525,7 +525,7 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
*/
|
||||
+ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
NSAssert(PL__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
ALMarginAxis marginAxis;
|
||||
switch (axis) {
|
||||
case ALAxisVertical:
|
||||
@@ -547,6 +547,6 @@ static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
return marginAxis;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
@end
|
||||
+10
-10
@@ -29,9 +29,9 @@
|
||||
|
||||
|
||||
// Using generics with NSMutableArray is so common in the internal implementation of PureLayout that it gets a dedicated preprocessor macro for better readability.
|
||||
#define __NSMutableArray_of(type) __PL_GENERICS(NSMutableArray, type)
|
||||
#define PL__NSMutableArray_of(type) PL__GENERICS(NSMutableArray, type)
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
PL__ASSUME_NONNULL_BEGIN
|
||||
|
||||
/** 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. */
|
||||
@@ -57,7 +57,7 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = (CGFloat)0.00001; // very small flo
|
||||
|
||||
- (ALView *)al_commonSuperviewOfViews;
|
||||
- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews;
|
||||
- (__NSArray_of(ALView *) *)al_copyViewsOnly;
|
||||
- (PL__NSArray_of(ALView *) *)al_copyViewsOnly;
|
||||
|
||||
@end
|
||||
|
||||
@@ -68,20 +68,20 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = (CGFloat)0.00001; // very small flo
|
||||
@interface NSLayoutConstraint (PureLayoutInternal)
|
||||
|
||||
+ (BOOL)al_preventAutomaticConstraintInstallation;
|
||||
+ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints;
|
||||
+ (PL__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints;
|
||||
+ (BOOL)al_isExecutingPriorityConstraintsBlock;
|
||||
+ (ALLayoutPriority)al_currentGlobalConstraintPriority;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
+ (NSString *)al_currentGlobalConstraintIdentifier;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
+ (nullable NSString *)al_currentGlobalConstraintIdentifier;
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint;
|
||||
+ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute;
|
||||
+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__PureLayout_MinBaseSDK_iOS_8_0
|
||||
+ (ALMargin)al_marginForEdge:(ALEdge)edge;
|
||||
+ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
PL__ASSUME_NONNULL_END
|
||||
+24
-20
@@ -29,37 +29,41 @@
|
||||
#define PureLayoutDefines_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// check the code in <Foundation/NSObjCRuntime.h> - <Availability.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 PL__PureLayout_MinBaseSDK_iOS_8_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1)
|
||||
#define PL__PureLayout_MinBaseSDK_iOS_9_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_8_4)
|
||||
#define PL__PureLayout_MinBaseSDK_iOS_11_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3)
|
||||
#define PL__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 PL__PureLayout_MinSysVer_iOS_7_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
|
||||
#define PL__PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
|
||||
#define PL__PureLayout_MinSysVer_iOS_9_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_8_x_Max)
|
||||
#define PL__PureLayout_MinSysVer_iOS_10_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max)
|
||||
#define PL__PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4)
|
||||
|
||||
// Define some preprocessor macros that allow nullability annotations to be adopted in a backwards-compatible manner.
|
||||
#if __has_feature(nullability)
|
||||
# define __PL_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
|
||||
# define __PL_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
|
||||
# define PL__ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
|
||||
# define PL__ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
|
||||
#else
|
||||
# define __PL_ASSUME_NONNULL_BEGIN
|
||||
# define __PL_ASSUME_NONNULL_END
|
||||
# define PL__ASSUME_NONNULL_BEGIN
|
||||
# define PL__ASSUME_NONNULL_END
|
||||
#endif
|
||||
|
||||
// Define some preprocessor macros that allow generics to be adopted in a backwards-compatible manner.
|
||||
#if __has_feature(objc_generics)
|
||||
# define __PL_GENERICS(class, ...) class<__VA_ARGS__>
|
||||
# define PL__GENERICS(class, ...) class<__VA_ARGS__>
|
||||
#else
|
||||
# define __PL_GENERICS(class, ...) class
|
||||
# define PL__GENERICS(class, ...) class
|
||||
#endif
|
||||
|
||||
// Using generics with NSArray is so common in PureLayout that it gets a dedicated preprocessor macro for better readability.
|
||||
#define __NSArray_of(type) __PL_GENERICS(NSArray, type)
|
||||
#define PL__NSArray_of(type) PL__GENERICS(NSArray, type)
|
||||
|
||||
// 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
|
||||
#if TARGET_OS_IPHONE || TARGET_OS_TV
|
||||
# import <UIKit/UIKit.h>
|
||||
# define ALView UIView
|
||||
# define ALEdgeInsets UIEdgeInsets
|
||||
@@ -135,13 +139,13 @@ typedef NS_ENUM(NSInteger, ALAxis) {
|
||||
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
|
||||
#if PL__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 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
};
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
#if PL__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) {
|
||||
@@ -167,7 +171,7 @@ typedef NS_ENUM(NSInteger, ALMarginAxis) {
|
||||
ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins
|
||||
};
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__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. */
|
||||
@@ -196,7 +200,7 @@ typedef NS_ENUM(NSInteger, ALAttribute) {
|
||||
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
|
||||
#if PL__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. */
|
||||
@@ -215,7 +219,7 @@ typedef NS_ENUM(NSInteger, ALAttribute) {
|
||||
ALAttributeMarginAxisVertical = ALMarginAxisVertical,
|
||||
/** A horizontal line equidistant from the view's top and bottom margins. */
|
||||
ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* PL__PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
};
|
||||
|
||||
/** A block containing method calls to the PureLayout API. Takes no arguments and has no return value. */
|
||||
|
||||
Generated
+27
-7
@@ -1,5 +1,5 @@
|
||||
# [](#)
|
||||
[](https://travis-ci.org/PureLayout/PureLayout) [](https://coveralls.io/r/PureLayout/PureLayout) [](http://cocoapods.org/?q=PureLayout) [](http://cocoapods.org/?q=PureLayout) [](LICENSE)
|
||||
[](https://travis-ci.org/PureLayout/PureLayout) [](http://cocoapods.org/pods/PureLayout) [](http://cocoapods.org/pods/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 a cross-platform Objective-C library that works (and looks!) great in Swift. It is fully backwards-compatible with all versions of iOS and OS X that support Auto Layout.
|
||||
|
||||
@@ -100,7 +100,7 @@ Additionally, there is one generic attribute type, `ALAttribute`, which is effec
|
||||
### [`UIView`/`NSView`](PureLayout/PureLayout/ALView%2BPureLayout.h)
|
||||
```
|
||||
- autoSetContent(CompressionResistance|Hugging)PriorityForAxis:
|
||||
- autoCenterInSuperview(Margins): // Margins variant iOS 8.0+ only
|
||||
- autoCenterInSuperview(Margins) // Margins variant iOS 8.0+ only
|
||||
- autoAlignAxisToSuperview(Margin)Axis: // Margin variant iOS 8.0+ only
|
||||
- autoPinEdgeToSuperview(Edge:|Margin:)(withInset:) // Margin variant iOS 8.0+ only
|
||||
- autoPinEdgesToSuperview(Edges|Margins)(WithInsets:)(excludingEdge:) // Margins variant iOS 8.0+ only
|
||||
@@ -110,6 +110,8 @@ Additionally, there is one generic attribute type, `ALAttribute`, which is effec
|
||||
- autoSetDimension(s)ToSize:
|
||||
- autoConstrainAttribute:toAttribute:ofView:(withOffset:|withMultiplier:)
|
||||
- autoPinTo(Top|Bottom)LayoutGuideOfViewController:withInset: // iOS only
|
||||
- autoPinEdgeToSuperviewSafeArea: // iOS 11.0+ only
|
||||
- autoPinEdgeToSuperviewSafeArea:withInset: // iOS 11.0+ only
|
||||
```
|
||||
|
||||
### [`NSArray`](PureLayout/PureLayout/NSArray%2BPureLayout.h)
|
||||
@@ -144,16 +146,28 @@ Additionally, there is one generic attribute type, `ALAttribute`, which is effec
|
||||
### Sample Code (Swift)
|
||||
PureLayout dramatically simplifies writing Auto Layout code. Let's take a quick look at some examples, using PureLayout from Swift.
|
||||
|
||||
Initialize the view using PureLayout initializer:
|
||||
|
||||
```swift
|
||||
let view1 = UIView(forAutoLayout: ())
|
||||
```
|
||||
|
||||
If you need to use a different initializer (e.g. in `UIView` subclass), you can also use `configureForAutoLayout`:
|
||||
|
||||
```
|
||||
view1.configureForAutoLayout() // alternative to UIView.init(forAutoLayout: ())
|
||||
```
|
||||
|
||||
Here's a constraint between two views created (and automatically activated) using PureLayout:
|
||||
|
||||
```swift
|
||||
view1.autoPinEdge(.Top, toEdge: .Bottom, ofView: view2)
|
||||
view1.autoPinEdge(.top, toEdge: .bottom, ofView: view2)
|
||||
```
|
||||
|
||||
Without PureLayout, here's the equivalent code you'd have to write using Apple's Foundation API directly:
|
||||
|
||||
```swift
|
||||
NSLayoutConstraint(item: view1, attribute: .Top, relatedBy: .Equal, toItem: view2, attribute: .Bottom, multiplier: 1.0, constant: 0.0).active = true
|
||||
NSLayoutConstraint(item: view1, attribute: .top, relatedBy: .equal, toItem: view2, attribute: .bottom, multiplier: 1.0, constant: 0.0).active = true
|
||||
```
|
||||
|
||||
Many APIs of PureLayout create multiple constraints for you under the hood, letting you write highly readable layout code:
|
||||
@@ -163,13 +177,19 @@ Many APIs of PureLayout create multiple constraints for you under the hood, lett
|
||||
logoImageView.autoCenterInSuperview()
|
||||
|
||||
// 4 constraints created & activated in one line!
|
||||
textContentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 20.0, left: 5.0, bottom: 10.0, right: 5.0))
|
||||
textContentView.autoPinEdgesToSuperviewEdges(with insets: UIEdgeInsets(top: 20.0, left: 5.0, bottom: 10.0, right: 5.0))
|
||||
```
|
||||
|
||||
PureLayout always returns the constraints it creates so you have full control:
|
||||
|
||||
```swift
|
||||
let constraint = skinnyView.autoMatchDimension(.Height, toDimension: .Width, ofView: tallView)
|
||||
let constraint = skinnyView.autoMatchDimension(.height, toDimension: .width, ofView: tallView)
|
||||
```
|
||||
|
||||
PureLayout supports safearea with iOS 11.0+:
|
||||
|
||||
```swift
|
||||
view2.autoPinEdge(toSuperviewSafeArea: .top)
|
||||
```
|
||||
|
||||
PureLayout supports all Auto Layout features including inequalities, priorities, layout margins, identifiers, and much more. It's a comprehensive, developer-friendly way to use Auto Layout.
|
||||
@@ -192,7 +212,7 @@ There are quite a few different ways to implement Auto Layout. Here is a quick o
|
||||
* 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)
|
||||
* Apple [Visual Format Language](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage.html)
|
||||
* Pros: Concise; convenient
|
||||
* Cons: Doesn't support some use cases; lacks compile-time checking and safety; must learn syntax; hard to debug
|
||||
* Apple Interface Builder
|
||||
|
||||
Reference in new issue
Block a user