ASLayoutSpec(Subclassing) Category Reference

Declared in ASLayoutSpec+Subclasses.h

– layoutElementToAddFromLayoutElement:

Helper method for finalLayoutElement support

- (id<ASLayoutElement>)layoutElementToAddFromLayoutElement:(id<ASLayoutElement>)child

Discussion

Warning: If you are getting recursion crashes here after implementing finalLayoutElement, make sure that you are setting isFinalLayoutElement flag to YES. This must be one BEFORE adding a child to the new ASLayoutElement.

For example: - (idASLayoutElement)finalLayoutElement { ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init]; insetSpec.insets = UIEdgeInsetsMake(10,10,10,10); insetSpec.isFinalLayoutElement = YES; [insetSpec setChild:self]; return insetSpec; }

Declared In

ASLayoutSpec+Subclasses.h

– setChild:atIndex:

Adds a child with the given identifier to this layout spec.

- (void)setChild:(id<ASLayoutElement>)child atIndex:(NSUInteger)index

Parameters

child

A child to be added.

index

An index associated with the child.

Discussion

Every ASLayoutSpec must act on at least one child. The ASLayoutSpec base class takes the responsibility of holding on to the spec children. Some layout specs, like ASInsetLayoutSpec, only require a single child.

For layout specs that require a known number of children (ASBackgroundLayoutSpec, for example) a subclass can use the setChild method to set the “primary” child. It should then use this method to set any other required children. Ideally a subclass would hide this from the user, and use the setChild:forIndex: internally. For example, ASBackgroundLayoutSpec exposes a backgroundChild property that behind the scenes is calling setChild:forIndex:.

Declared In

ASLayoutSpec+Subclasses.h

– childAtIndex:

Returns the child added to this layout spec using the given index.

- (nullable id<ASLayoutElement>)childAtIndex:(NSUInteger)index

Parameters

index

An identifier associated with the the child.

Declared In

ASLayoutSpec+Subclasses.h