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
230
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
120
Working with Legacy Code (Łódź)
maciejoczko
0
51
iOS TDD Workshop (Gdańsk)
maciejoczko
1
79
UICollectionView Introduction
maciejoczko
0
60
Working With Legacy Code - iOS TDD Workshop
maciejoczko
0
160
Depenedency Injection in iOS
maciejoczko
0
68
Other Decks in Programming
See All in Programming
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
6
990
RubyKaigi Dev Meeting 2025
tenderlove
1
110
「影響が少ない」を自分の目でみてみる
o0h
PRO
2
1.1k
Do Dumb Things
mitsuhiko
0
430
The Weight of Data: Rethinking Cloud-Native Systems for the Age of AI
hollycummins
0
280
趣味全開のAITuber開発
kokushin
0
200
メモリウォールを超えて:キャッシュメモリ技術の進歩
kawayu
0
1.9k
MCP世界への招待: AIエンジニアが創る次世代エージェント連携の世界
gunta
4
900
PHPで書いたAPIをGoに書き換えてみた 〜パフォーマンス改善の可能性を探る実験レポート〜
koguuum
0
150
Going Structural with Named Tuples
bishabosha
0
200
Empowering Developers with HTML-Aware ERB Tooling @ RubyKaigi 2025, Matsuyama, Ehime
marcoroth
2
490
[NG India] Event-Based State Management with NgRx SignalStore
markostanimirovic
1
150
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
[RailsConf 2023] Rails as a piece of cake
palkan
54
5.4k
Code Reviewing Like a Champion
maltzj
522
40k
The Pragmatic Product Professional
lauravandoore
33
6.5k
Building Adaptive Systems
keathley
41
2.5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Building Applications with DynamoDB
mza
94
6.3k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
Automating Front-end Workflow
addyosmani
1369
200k
A Modern Web Designer's Workflow
chriscoyier
693
190k
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