- add - (BOOL) removeObjectsWithClass:(Class _Nonnull) class
- fix - (id _Nonnull) saveLocally:(id _Nonnull) object - upgrade libraries
This commit is contained in:
1 parent
874707e958
commit
99e06e67db
239 files changed
+13154
-6570
No files matched your search
@@ -69,6 +69,29 @@ PL__ASSUME_NONNULL_BEGIN
|
||||
|
||||
#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 *)autoPinEdgeToSuperviewSafeArea:(ALEdge)edge;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview anchor/edge with an inset. */
|
||||
- (NSLayoutConstraint *)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 *)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 *) *)autoPinEdgesToSuperviewSafeArea;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview anchors/edges with the given edge insets. */
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)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 *) *)autoPinEdgesToSuperviewSafeAreaWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
#pragma mark Pin Edges to Superview
|
||||
|
||||
@@ -95,12 +118,18 @@ PL__ASSUME_NONNULL_BEGIN
|
||||
/** 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. */
|
||||
- (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. */
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
|
||||
|
||||
|
||||
+339
-41
@@ -80,7 +80,7 @@
|
||||
*/
|
||||
- (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;
|
||||
@@ -109,7 +109,7 @@
|
||||
*/
|
||||
- (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;
|
||||
@@ -133,6 +133,234 @@
|
||||
#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,7 +414,7 @@
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
- (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges
|
||||
{
|
||||
@@ -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.
|
||||
*/
|
||||
- (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,22 +445,42 @@
|
||||
@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.
|
||||
*/
|
||||
- (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;
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
- (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,22 +573,42 @@
|
||||
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.
|
||||
*/
|
||||
- (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;
|
||||
}
|
||||
@@ -360,7 +660,6 @@
|
||||
return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)toEdge ofView:otherView withOffset:offset relation:relation];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Align Axes
|
||||
|
||||
/**
|
||||
@@ -486,7 +785,7 @@
|
||||
*/
|
||||
- (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;
|
||||
@@ -721,7 +1020,6 @@
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
|
||||
#pragma mark Internal Methods
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
- (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]]) {
|
||||
@@ -146,7 +146,7 @@
|
||||
- (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]]) {
|
||||
@@ -171,7 +171,7 @@
|
||||
- (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]]) {
|
||||
@@ -197,7 +197,7 @@
|
||||
- (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;
|
||||
@@ -217,7 +217,7 @@
|
||||
*/
|
||||
- (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;
|
||||
@@ -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]]) {
|
||||
@@ -407,7 +407,7 @@
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally
|
||||
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
PL__NSArray_of(ALView *) *views = [self al_copyViewsOnly];
|
||||
NSUInteger numberOfViews = [views count];
|
||||
ALView *commonSuperview = [views al_commonSuperviewOfViews];
|
||||
@@ -493,7 +493,7 @@
|
||||
*/
|
||||
- (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];
|
||||
|
||||
+9
-9
@@ -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];
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
|
||||
// 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
|
||||
|
||||
@@ -68,11 +68,11 @@ 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 PL__PureLayout_MinBaseSDK_iOS_8_0 || PL__PureLayout_MinBaseSDK_OSX_10_10
|
||||
+ (NSString *)al_currentGlobalConstraintIdentifier;
|
||||
+ (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;
|
||||
|
||||
@@ -29,14 +29,18 @@
|
||||
#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 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 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.
|
||||
|
||||
Generated
+13
-5
@@ -1,5 +1,5 @@
|
||||
# [](#)
|
||||
[](https://travis-ci.org/PureLayout/PureLayout) [](https://coveralls.io/r/PureLayout/PureLayout) [](http://cocoapods.org/pods/PureLayout) [](http://cocoapods.org/pods/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.
|
||||
|
||||
@@ -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)
|
||||
@@ -147,13 +149,13 @@ PureLayout dramatically simplifies writing Auto Layout code. Let's take a quick
|
||||
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 +165,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.
|
||||
|
||||
Reference in new issue
Block a user