Skip to content

Commit 9ab9fdb

Browse files
committed
Added support for header and footer views when using the flow layout.
1 parent f82f9d8 commit 9ab9fdb

23 files changed

Lines changed: 916 additions & 35 deletions

Examples/FlowLayoutHorizontal/CollectionExample/ViewController.m

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ @implementation ViewController {
1313
}
1414

1515
static NSString *cellIdentifier = @"TestCell";
16-
static NSString *viewIdentifier = @"TestView";
16+
static NSString *headerViewIdentifier = @"Test Header View";
17+
static NSString *footerViewIdentifier = @"Test Footer View";
1718

1819

1920
#pragma mark -
@@ -51,7 +52,9 @@ - (void)viewDidLoad {
5152

5253
data = @[
5354
@[@"One", @"Two", @"Three"],
54-
@[@"Four", @"Five", @"Six"]
55+
@[@"Four", @"Five", @"Six"],
56+
@[],
57+
@[@"Seven"],
5558
];
5659
}
5760

@@ -79,11 +82,18 @@ - (PSUICollectionViewCell *)collectionView:(PSUICollectionView *)collectionView
7982
}
8083

8184
- (PSUICollectionReusableView *)collectionView:(PSUICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
82-
PSUICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:PSTCollectionElementKindSectionHeader withReuseIdentifier:viewIdentifier forIndexPath:indexPath];
85+
NSString *identifier = nil;
86+
87+
if ([kind isEqualToString:PSTCollectionElementKindSectionHeader]) {
88+
identifier = headerViewIdentifier;
89+
} else if ([kind isEqualToString:PSTCollectionElementKindSectionFooter]) {
90+
identifier = footerViewIdentifier;
91+
}
92+
PSUICollectionReusableView *supplementaryView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:identifier forIndexPath:indexPath];
8393

8494
// TODO Setup view
8595

86-
return headerView;
96+
return supplementaryView;
8797
}
8898

8999
@end

Examples/FlowLayoutHorizontal/CollectionExample/en.lproj/MainStoryboard.storyboard

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="10" minimumInteritemSpacing="10" id="lm0-GF-aK5">
2020
<size key="itemSize" width="250" height="245"/>
2121
<size key="headerReferenceSize" width="30" height="500"/>
22-
<size key="footerReferenceSize" width="0.0" height="0.0"/>
22+
<size key="footerReferenceSize" width="50" height="500"/>
2323
<inset key="sectionInset" minX="10" minY="0.0" maxX="20" maxY="0.0"/>
2424
</collectionViewFlowLayout>
2525
<cells>
@@ -43,11 +43,16 @@
4343
<color key="backgroundColor" red="1" green="1" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
4444
</collectionViewCell>
4545
</cells>
46-
<collectionReusableView key="sectionHeaderView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="TestView" id="7EZ-10-Zt3">
46+
<collectionReusableView key="sectionHeaderView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Test Header View" id="7EZ-10-Zt3">
4747
<rect key="frame" x="0.0" y="0.0" width="30" height="500"/>
4848
<autoresizingMask key="autoresizingMask"/>
4949
<color key="backgroundColor" red="0.0" green="1" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
5050
</collectionReusableView>
51+
<collectionReusableView key="sectionFooterView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Test Footer View" id="HFq-Mx-g3M">
52+
<rect key="frame" x="310" y="0.0" width="50" height="500"/>
53+
<autoresizingMask key="autoresizingMask"/>
54+
<color key="backgroundColor" red="0.5" green="0.0" blue="0.5" alpha="1" colorSpace="calibratedRGB"/>
55+
</collectionReusableView>
5156
<connections>
5257
<outlet property="dataSource" destination="2" id="xax-pR-9bi"/>
5358
<outlet property="delegate" destination="2" id="nRY-TP-dCW"/>
@@ -82,7 +87,7 @@
8287
<class className="ViewController" superclassName="UIViewController">
8388
<source key="sourceIdentifier" type="project" relativePath="./Classes/ViewController.h"/>
8489
<relationships>
85-
<relationship kind="outlet" name="collectionView" candidateClass="UICollectionView"/>
90+
<relationship kind="outlet" name="collectionView" candidateClass="PSUICollectionView"/>
8691
</relationships>
8792
</class>
8893
</classes>

0 commit comments

Comments
 (0)