Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, you'll need to add attributes that describe a reusable view for each cell that you need one for. you can add these attributes for each cell based on the attributes that should already be there for laying out your cells. you can do this in layoutAttributesForElementInRect.</p> <pre><code>- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { //first get a copy of all layout attributes that represent the cells. you will be modifying this collection. NSMutableArray *allAttributes = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; //go through each cell attribute for (UICollectionViewLayoutAttributes *attributes in [super layoutAttributesForElementsInRect:rect]) { //add a title and a detail supp view for each cell attribute to your copy of all attributes [allAttributes addObject:[self layoutAttributesForSupplementaryViewOfKind:SomeCellDetailsKind atIndexPath:[attributes indexPath]]]; [allAttributes addObject:[self layoutAttributesForSupplementaryViewOfKind:SomeCellTitleKind atIndexPath:[attributes indexPath]]]; } //return the updated attributes list along with the layout info for the supp views return allAttributes; } -(UICollectionViewLayoutAttributes*) layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ //create a new layout attributes to represent this reusable view UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:kind withIndexPath:indexPath]; if(attrs){ //get the attributes for the related cell at this index path UICollectionViewLayoutAttributes *cellAttrs = [super layoutAttributesForItemAtIndexPath:indexPath]; if(kind == SomeCellDetailsKind){ //position this reusable view relative to the cells frame CGRect frame = cellAttrs.frame; frame.origin.y += (frame.size.height - _detailHeight); frame.size.height = _detailHeight; attrs.frame = frame; } if(kind == SomeCellTitleKind){ //position this reusable view relative to the cells frame CGRect frame = cellAttrs.frame; frame.origin.y -= _titleHeight; //+= frame.size.height; //( - frame.size.height; frame.size.height = _titleHeight; attrs.frame = frame; } } return attrs; } </code></pre> <p>Then you can implement collectionViewForSupplementaryElementOfKindAtIndexPath to describe what the view should look like. </p> <p>And like Derrick Hathaway mentioned, the flow layout will not size row heights considering the heights of the supp views so make sure to adjust your min row height on your collection view appropriately.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload