Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
UICollectionView Basics and Flow Layout
Search
Maciej Oczko
November 29, 2014
Programming
0
240
UICollectionView Basics and Flow Layout
Basics of UICollectionView and Flow Layout for workshops in Kraków.
Maciej Oczko
November 29, 2014
Tweet
Share
More Decks by Maciej Oczko
See All by Maciej Oczko
Dependency Injection on iOS
maciejoczko
1
130
Working with Legacy Code (Łódź)
maciejoczko
0
56
iOS TDD Workshop (Gdańsk)
maciejoczko
1
82
UICollectionView Introduction
maciejoczko
0
63
Working With Legacy Code - iOS TDD Workshop
maciejoczko
0
170
Depenedency Injection in iOS
maciejoczko
0
72
Other Decks in Programming
See All in Programming
AgentCoreとHuman in the Loop
har1101
5
240
Oxlintはいいぞ
yug1224
5
1.3k
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
240
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
290
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
CSC307 Lecture 09
javiergs
PRO
1
840
高速開発のためのコード整理術
sutetotanuki
1
400
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
130
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
740
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
590
Featured
See All Featured
Unsuck your backbone
ammeep
671
58k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
120
Designing for Timeless Needs
cassininazir
0
130
GitHub's CSS Performance
jonrohan
1032
470k
Speed Design
sergeychernyshev
33
1.5k
A better future with KSS
kneath
240
18k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
130
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Transcript
UICollectionView #UICollectionViewKrakow
@maciejoczko #UICollectionViewKrakow
Introduction #UICollectionViewKrakow
UI != NS #UICollectionViewKrakow
#UICollectionViewKrakow
“UICollectionView is the new UITableView. It's that important. NSHipster #UICollectionViewKrakow
“UICollectionView is awesome! My Friend #UICollectionViewKrakow
“The UICollectionView class manages an ordered collection of data items
and presents them using customizable layouts. Apple #UICollectionViewKrakow
UICollectionView allows » to have totally custom layout » to
dynamically change layouts » to have interactive transitions between layouts #UICollectionViewKrakow
UICollectionView is » subclass of UIScrollView » sibling of UITableView
#UICollectionViewKrakow
UICollectionView Alloc Init » initWithFrame:collectionViewLayout: » UICollectionViewController #UICollectionViewKrakow
UICollectionView is mostly about... #UICollectionViewKrakow
Grids #UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
Anatomy of Collection View #UICollectionViewKrakow
Cell Supplementary View Decoration View #UICollectionViewKrakow
Cell For Item » Tied to content » No predefined
style » New way of creation » UICollectionReusableView subclass #UICollectionViewKrakow
Supplementary View » Tied to content but separate from cells
» Driven by section data » View of a kind » UICollectionReusableView subclass #UICollectionViewKrakow
Decoration View » Not tied to content » Created in
layout subclass » UICollectionReusableView subclass #UICollectionViewKrakow
Layout #UICollectionViewKrakow
Layout: Position #UICollectionViewKrakow
Layout: animations & transitions #UICollectionViewKrakow
How to create custom layout? #UICollectionViewKrakow
Derive from UICollectionViewLayout #UICollectionViewKrakow
Override methods collectionViewContentSize layoutAttributesForElementsInRect: layoutAttributesForItemAtIndexPath: layoutAttributesForSupplementaryViewOfKind:atIndexPath: layoutAttributesForDecorationViewOfKind:atIndexPath: shouldInvalidateLayoutForBoundsChange: #UICollectionViewKrakow
Override even more... prepareForCollectionViewUpdates: initialLayoutAttributesForAppearingItemAtIndexPath: initialLayoutAttributesForAppearingSupplementaryElementOfKind:atIndexPath: initialLayoutAttributesForAppearingDecorationElementOfKind:atIndexPath: finalLayoutAttributesForDisappearingItemAtIndexPath: finalLayoutAttributesForDisappearingSupplementaryElementOfKind:atIndexPath: finalLayoutAttributesForDisappearingDecorationElementOfKind:atIndexPath:
finalizeCollectionViewUpdates #UICollectionViewKrakow
Attributes1 Object that manages the layout-related attributes for a given
item. 1 UICollectionViewLayoutAttributes #UICollectionViewKrakow
Attributes1 » frame, center, size » alpha, hidden » zIndex
» transform 3D 1 UICollectionViewLayoutAttributes #UICollectionViewKrakow
Layout: Recap » positioning » animations & transitions » subclassing
» UICollectionViewLayoutAttributes #UICollectionViewKrakow
Data Source Delegate #UICollectionViewKrakow
Delegate » Selection & highlight tracking callbacks » Tracking the
removal of views » Layout transition callback » Menu actions callbacks #UICollectionViewKrakow
Data Source - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section -
(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath #UICollectionViewKrakow
Data Source - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath #UICollectionViewKrakow
collectionView:cellForItemAtIndexPath: MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@”MY_CELL_ID”]; if (!cell) { cell
= . . . } // Configure the cell's content return cell; #UICollectionViewKrakow
collectionView:cellForItemAtIndexPath: MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@”MY_CELL_ID” forIndexPath:indexPath]; // Configure the
cell's content return cell; #UICollectionViewKrakow
View class registration [collectionView registerClass:[MyCell class] forCellWithReuseIdentifier:@“MY_CELL_ID”] [collectionView registerClass:[MySupView class]
forSupplementaryViewOfKind:@“MY_KIND” withReuseIdentifier:@“MY_CELL_ID”] [collectionView registerClass:[MyDecoView class] forDecorationViewOfKind:@“MY_KIND”] #UICollectionViewKrakow
Flow Layout #UICollectionViewKrakow
Flow Layout3 » Line oriented » Grid or group of
lines » Predefined supplementary views: header & footer 3 UICollectionViewFlowLayout #UICollectionViewKrakow
Flow Layout: Customization » itemsize » inter item spacing »
line spacing » scroll direction2 » reference sizes » section insets 2 Can't be set through UICollectionViewDelegateFlowLayout delegate. #UICollectionViewKrakow
Flow Layout #UICollectionViewKrakow
RECAP UICollectionView Anatomy Layout & Attributes Data Source & Delegate
Flow Layout #UICollectionViewKrakow
https://github.com/mobile-academy/ ios-uicollectionview-seed #UICollectionViewKrakow
Task Create simple CollectionViewController with flow layout and inject it
to RootViewController as its content. // AppDelegate.m CollectionViewDataSource *dataSource = [CollectionViewDataSource new]; CollectionViewController *cVC = [[CollectionViewController alloc] initWithDataSource:dataSource]; RootViewController *rootVC = [[RootViewController alloc] initWithContentController:cVC]; self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootVC]; #UICollectionViewKrakow
#UICollectionViewKrakow #UICollectionViewKrakow
Thanks! @maciejoczko #UICollectionViewKrakow