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
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
PipeCDのプラグイン化で目指すところ
warashi
1
310
チームのテスト力を総合的に鍛えて品質、スピード、レジリエンスを共立させる/Testing approach that improves quality, speed, and resilience
goyoki
5
1.2k
レベル1の開発生産性向上に取り組む − 日々の作業の効率化・自動化を通じた改善活動
kesoji
1
330
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1.2k
AIのメモリー
watany
6
130
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
280
Python型ヒント完全ガイド 初心者でも分かる、現代的で実践的な使い方
mickey_kubo
1
250
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
12
7.3k
TypeScriptでDXを上げろ! Hono編
yusukebe
3
830
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
2
16k
What's new in AppKit on macOS 26
1024jp
0
160
「App Intent」よくわからんけどすごい!
rinngo0302
1
120
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.6k
How to Think Like a Performance Engineer
csswizardry
25
1.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
We Have a Design System, Now What?
morganepeng
53
7.7k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
The Invisible Side of Design
smashingmag
301
51k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
KATA
mclloyd
30
14k
Six Lessons from altMBA
skipperchong
28
3.9k
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