Skip to content

Commit 6843303

Browse files
ajsecordianegordon
authored andcommitted
[Collections] Added custom Storyboard cell to the Storyboard example. (#1152)
1 parent 0b2db35 commit 6843303

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

components/Collections/examples/CollectionsStoryboardExample.m

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919
static const NSInteger kSectionCount = 10;
2020
static const NSInteger kSectionItemCount = 5;
21-
static NSString *const kReusableIdentifierItem = @"itemCellIdentifier";
21+
static NSString *const kReusableIdentifierItem = @"customCell";
22+
23+
@interface CollectionStoryboardExampleCell: UICollectionViewCell
24+
@property(nonatomic, weak) IBOutlet UILabel *label;
25+
@end
2226

2327
@implementation CollectionsStoryboardExample {
2428
NSMutableArray *_content;
@@ -36,10 +40,6 @@ - (void)viewDidLoad {
3640
[super viewDidLoad];
3741
self.title = @"Storyboard Demo";
3842

39-
// Register cell class.
40-
[self.collectionView registerClass:[MDCCollectionViewTextCell class]
41-
forCellWithReuseIdentifier:kReusableIdentifierItem];
42-
4343
// Populate content.
4444
_content = [NSMutableArray array];
4545
for (NSInteger i = 0; i < kSectionCount; i++) {
@@ -68,11 +68,15 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView
6868

6969
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
7070
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
71-
MDCCollectionViewTextCell *cell =
71+
CollectionStoryboardExampleCell *cell =
7272
[collectionView dequeueReusableCellWithReuseIdentifier:kReusableIdentifierItem
7373
forIndexPath:indexPath];
74-
cell.textLabel.text = _content[indexPath.section][indexPath.item];
74+
cell.label.text = _content[indexPath.section][indexPath.item];
75+
7576
return cell;
7677
}
7778

7879
@end
80+
81+
@implementation CollectionStoryboardExampleCell
82+
@end

components/Collections/examples/resources/CollectionsStoryboardExample.storyboard

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BMn-rM-e2q">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BMn-rM-e2q">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<scenes>
812
<!--CollectionsStoryboardExample-->
913
<scene sceneID="nRw-zU-Xbw">
1014
<objects>
1115
<collectionViewController title="CollectionsStoryboardExample" id="BMn-rM-e2q" customClass="CollectionsStoryboardExample" sceneMemberID="viewController">
12-
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="H2V-rH-0Z8">
13-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
16+
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" misplaced="YES" dataMode="prototypes" id="H2V-rH-0Z8">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1418
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1519
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="eqs-fm-Qll">
1620
<size key="itemSize" width="50" height="50"/>
@@ -19,23 +23,26 @@
1923
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
2024
</collectionViewFlowLayout>
2125
<cells>
22-
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="firstCell" id="ya3-i3-i11">
26+
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="customCell" id="ya3-i3-i11" userLabel="customCell" customClass="CollectionStoryboardExampleCell">
2327
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
2428
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2529
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
2630
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
2731
<autoresizingMask key="autoresizingMask"/>
28-
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
29-
</view>
30-
</collectionViewCell>
31-
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="secondCell" id="ACF-5M-rsG">
32-
<rect key="frame" x="61" y="0.0" width="50" height="50"/>
33-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
34-
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
35-
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
36-
<autoresizingMask key="autoresizingMask"/>
37-
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
32+
<subviews>
33+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QSw-4r-pfz">
34+
<rect key="frame" x="4" y="15" width="42" height="21"/>
35+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
36+
<fontDescription key="fontDescription" type="italicSystem" pointSize="17"/>
37+
<nil key="textColor"/>
38+
<nil key="highlightedColor"/>
39+
</label>
40+
</subviews>
3841
</view>
42+
<color key="backgroundColor" red="0.8633875639571934" green="0.93266503655327992" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
43+
<connections>
44+
<outlet property="label" destination="QSw-4r-pfz" id="yUG-kP-cZg"/>
45+
</connections>
3946
</collectionViewCell>
4047
</cells>
4148
<connections>

0 commit comments

Comments
 (0)