123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848 |
- @implementation ALView (PureLayout)
- + (instancetype)newAutoLayoutView
- {
- ALView *view = [self new];
- view.translatesAutoresizingMaskIntoConstraints = NO;
- return view;
- }
- - (instancetype)initForAutoLayout
- {
- self = [self init];
- if (self) {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- }
- return self;
- }
- - (instancetype)configureForAutoLayout
- {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- return self;
- }
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview
- {
- PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
- [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]];
- [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]];
- return constraints;
- }
- - (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis
- {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- ALView *superview = self.superview;
- NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
- return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:superview];
- }
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins
- {
- PL__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
- [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]];
- [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]];
- return constraints;
- }
- - (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis
- {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- ALView *superview = self.superview;
- NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
- ALMarginAxis marginAxis = [NSLayoutConstraint al_marginAxisForAxis:axis];
- return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)marginAxis ofView:superview];
- }
- - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge
- {
- return [self autoPinEdgeToSuperviewEdge:edge withInset:0.0];
- }
- - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset
- {
- return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
- {
- 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) {
-
- inset = -inset;
- if (relation == NSLayoutRelationLessThanOrEqual) {
- relation = NSLayoutRelationGreaterThanOrEqual;
- } else if (relation == NSLayoutRelationGreaterThanOrEqual) {
- relation = NSLayoutRelationLessThanOrEqual;
- }
- }
- return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation];
- }
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges
- {
- return [self autoPinEdgesToSuperviewEdgesWithInsets:ALEdgeInsetsZero];
- }
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets
- {
- 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]];
- [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
- return constraints;
- }
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge
- {
- PL__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]];
- }
- return constraints;
- }
-
- - (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge
- {
- return [self autoPinEdgeToSuperviewMargin:edge relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation
- {
- 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) {
-
- if (relation == NSLayoutRelationLessThanOrEqual) {
- relation = NSLayoutRelationGreaterThanOrEqual;
- } else if (relation == NSLayoutRelationGreaterThanOrEqual) {
- relation = NSLayoutRelationLessThanOrEqual;
- }
- }
- ALMargin margin = [NSLayoutConstraint al_marginForEdge:edge];
- return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)margin ofView:superview withOffset:0.0 relation:relation];
- }
-
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins
- {
- PL__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 constraints;
- }
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge
- {
- PL__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]];
- }
- return constraints;
- }
- - (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView
- {
- return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:0.0];
- }
- - (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset
- {
- return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:offset relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
- {
- return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)toEdge ofView:otherView withOffset:offset relation:relation];
- }
- - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView
- {
- return [self autoAlignAxis:axis toSameAxisOfView:otherView withOffset:0.0];
- }
- - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset
- {
- return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withOffset:offset];
- }
- - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier
- {
- return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withMultiplier:multiplier];
- }
- - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView
- {
- return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:0.0];
- }
- - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset
- {
- return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:offset relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
- {
- return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withOffset:offset relation:relation];
- }
- - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier
- {
- return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation
- {
- return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withMultiplier:multiplier relation:relation];
- }
- - (PL__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size
- {
- 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;
- }
- - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size
- {
- return [self autoSetDimension:dimension toSize:size relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation
- {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:(ALAttribute)dimension];
- NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:size];
- [constraint autoInstall];
- return constraint;
- }
- - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis
- {
- NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
- if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
- [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
- [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
- }
- }
- - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis
- {
- NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
- if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
- [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
- [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
- }
- }
- - (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView
- {
- return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:0.0];
- }
- - (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset
- {
- return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:offset relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
- {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute];
- NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute];
- NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:1.0 constant:offset];
- [constraint autoInstall];
- return constraint;
- }
- - (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier
- {
- return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation
- {
- self.translatesAutoresizingMaskIntoConstraints = NO;
- NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute];
- NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute];
- NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:multiplier constant:0.0];
- [constraint autoInstall];
- return constraint;
- }
- - (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset
- {
- return [self autoPinToTopLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
- {
- 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];
- return constraint;
- } else {
-
- return [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:viewController.view withOffset:inset relation:relation];
- }
- }
- - (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset
- {
- return [self autoPinToBottomLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual];
- }
- - (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
- {
-
- inset = -inset;
- if (relation == NSLayoutRelationLessThanOrEqual) {
- relation = NSLayoutRelationGreaterThanOrEqual;
- } else if (relation == NSLayoutRelationGreaterThanOrEqual) {
- relation = NSLayoutRelationLessThanOrEqual;
- }
- 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];
- return constraint;
- } else {
-
- return [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:viewController.view withOffset:inset relation:relation];
- }
- }
- - (void)al_addConstraint:(NSLayoutConstraint *)constraint
- {
- [NSLayoutConstraint al_applyGlobalStateToConstraint:constraint];
- if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
- [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:constraint];
- } else {
- [self addConstraint:constraint];
- }
- }
- - (ALView *)al_commonSuperviewWithView:(ALView *)otherView
- {
- ALView *commonSuperview = nil;
- ALView *startView = self;
- do {
- if ([otherView isDescendantOfView:startView]) {
- commonSuperview = startView;
- }
- if ([otherView isDescendantOf:startView]) {
- commonSuperview = startView;
- }
- startView = startView.superview;
- } while (startView && !commonSuperview);
- NSAssert(commonSuperview, @"Can't constrain two views that do not share a common superview. Make sure that both views have been added into the same view hierarchy.");
- return commonSuperview;
- }
- - (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis
- {
- NSLayoutConstraint *constraint = nil;
- switch (attribute) {
- case ALAttributeVertical:
- NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeVertical.");
- constraint = [self autoAlignAxis:ALAxisVertical toSameAxisOfView:otherView];
- break;
- case ALAttributeHorizontal:
- NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeHorizontal.");
- constraint = [self autoAlignAxis:ALAxisHorizontal toSameAxisOfView:otherView];
- break;
- case ALAttributeBaseline:
- NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBaseline.");
- constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:otherView];
- break;
- case ALAttributeFirstBaseline:
- 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;
- case ALAttributeTop:
- NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeTop.");
- constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:otherView];
- break;
- case ALAttributeLeft:
- NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeft.");
- constraint = [self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:otherView];
- break;
- case ALAttributeBottom:
- NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBottom.");
- constraint = [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:otherView];
- break;
- case ALAttributeRight:
- NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeRight.");
- constraint = [self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:otherView];
- break;
- case ALAttributeLeading:
- NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeading.");
- constraint = [self autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:otherView];
- break;
- case ALAttributeTrailing:
- NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeTrailing.");
- constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:otherView];
- break;
-
-
- case ALAttributeWidth:
- case ALAttributeHeight:
- case ALAttributeMarginLeft:
- case ALAttributeMarginRight:
- case ALAttributeMarginTop:
- case ALAttributeMarginBottom:
- case ALAttributeMarginLeading:
- case ALAttributeMarginTrailing:
- case ALAttributeMarginAxisVertical:
- case ALAttributeMarginAxisHorizontal:
- default:
- NSAssert(nil, @"Unsupported attribute for alignment.");
- break;
- }
- return constraint;
- }
- @end
|