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
120
Working with Legacy Code (Łódź)
maciejoczko
0
53
iOS TDD Workshop (Gdańsk)
maciejoczko
1
81
UICollectionView Introduction
maciejoczko
0
62
Working With Legacy Code - iOS TDD Workshop
maciejoczko
0
170
Depenedency Injection in iOS
maciejoczko
0
69
Other Decks in Programming
See All in Programming
そのAPI、誰のため? Androidライブラリ設計における利用者目線の実践テクニック
mkeeda
2
1.8k
AI時代のUIはどこへ行く?
yusukebe
18
9.1k
AWS発のAIエディタKiroを使ってみた
iriikeita
1
190
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
340
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
510
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
Putting The Genie in the Bottle - A Crash Course on running LLMs on Android
iurysza
0
140
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
130
Flutter with Dart MCP: All You Need - 박제창 2025 I/O Extended Busan
itsmedreamwalker
0
150
🔨 小さなビルドシステムを作る
momeemt
4
690
Navigating Dependency Injection with Metro
zacsweers
3
2.5k
Android 16 × Jetpack Composeで縦書きテキストエディタを作ろう / Vertical Text Editor with Compose on Android 16
cc4966
2
270
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Building an army of robots
kneath
306
46k
Gamification - CAS2011
davidbonilla
81
5.4k
Balancing Empowerment & Direction
lara
3
620
How to Think Like a Performance Engineer
csswizardry
26
1.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
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