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
SnapKit
Search
USAMI Kosuke
April 26, 2016
Programming
0
760
SnapKit
http://kanmoba.connpass.com/event/28416/
USAMI Kosuke
April 26, 2016
Tweet
Share
More Decks by USAMI Kosuke
See All by USAMI Kosuke
Onsager代数とその周辺 / Onsager algebra tsudoi
usamik26
0
530
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
110
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
280
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
430
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
690
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
610
UICollectionView Compositional Layout
usamik26
0
680
Coding Swift with Visual Studio Code and Docker
usamik26
0
450
Swift Extension for Visual Studio Code
usamik26
2
910
Other Decks in Programming
See All in Programming
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
イベント駆動で成長して委員会
happymana
1
330
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
受け取る人から提供する人になるということ
little_rubyist
0
250
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
Ethereum_.pdf
nekomatu
0
460
flutterkaigi_2024.pdf
kyoheig3
0
150
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
It's Worth the Effort
3n
183
27k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Gamification - CAS2011
davidbonilla
80
5k
Rails Girls Zürich Keynote
gr2m
94
13k
Fireside Chat
paigeccino
34
3k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Six Lessons from altMBA
skipperchong
27
3.5k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Transcript
SnapKit Auto Layout Library USAMI Kosuke Fenrir Inc.
View Layout for iOS & OS X » Auto Layout
Λ͏ » Auto Layout ΛΘͳ͍ » ͪͳΈʹʮAuto Layout ʯͰ͢
Auto Layout » Storyboard ্Ͱઃఆ » Source Code ্Ͱهड़ »
ͪͳΈʹʮStoryboard ʯͰ͢ » ͱ͍͑ɺݻࣥͤͣʹॊೈʹߟ͍͑ͨ
How to code Auto Layout ? » View Λ Storyboard
Ͱͳ͘ίʔυͰ࣮͍ͨ͜͠ͱ͕͋Δ » ͦͷͱ͖ Auto Lauout ίʔυͰ࣮͍ͨ͠ » ͦΜͳͱ͖ʹͲ͏͢Δʁ » ɾɾɾͱ͍͏ͷ͕ࠓճͷຊͰ͢ɻ
Auto Layout Coding
How to code Constraint ? Auto Layout ΛίʔυͰॻ͘ͱͭ·Γɾɾɾ » Constraintʢ੍ʣΛίʔυͰॻ͘ʹʁ
ͱ͍͏͜ͱ
iOS & OS X SDK » NSLayoutConstraint class » Visual
Format Language » NSLayoutAnchor class
NSLayoutConstraint NSLayoutConstraint( item: myView, attribute: .Left, relatedBy: .Equal, toItem: view,
attribute: . Left, multiplier: 1.0, constant: 0.0).active = true » ͬͱ Basic ͳํ๏ » ͻͱͭͷ؆୯ͳ੍ͷͨΊʹ͜Ε͚ͩॻ͔ͳ͍ͱ͍͚ͳ͍
Visual Format Language let constraints = NSLayoutConstraint.constraintsWithVisualFormat( "|-[myView]-|", options:.AlignAllTop ,
metrics: nil, views: ["myView" : myView]) NSLayoutConstraint.activateConstraints(constraints) » "|-[myView]-|" : ΤϥʔϩάͰΑ͘ݟ͔͚ΔΞϨ » ੍ͷจ๏ΛίϯύΠϥ͕νΣοΫͯ͘͠Εͳ͍
NSLayoutAnchor myView.leftAnchor .constraintEqualToAnchor(view.layoutGuides.leftAnchor) .active = true » iOS 9 and
later / OS X 10.11 and later » ͕݅߹͏ͳΒɺΘΓͱΞϦͩͱࢥ͏ͷͰݕ౼͍ͨ͠
ͬͱ͍͍खஈ͕ͳ͍͔ʁ » ඪ४ͷํ๏Ͱॻ͖ʹ͍͘ͷ͕ݱঢ় » Auto Layout ΛίʔυͰॻ͘ͳɺͱݴΘΕͯෆࢥٞͰͳ͍
SnapKit
SnapKit » http://snapkit.io/ » Auto Layout Library » For Swift
2 » ެࣜͰ Auto Layout DSL ͱݴ͍ͬͯΔ͕ɺSwift ͷจ๏ͦͷͷ
ิ : Masonry » Ҏલ Masonry ͱ͍͏ Objective-C ϥΠϒϥϦͩͬͨ »
SnapKit = Masonry ͷ Swift ൛ » Masonry ࣌ Objective-C ͬΆ͘ͳͯ͘ DSL ײ͕ڧ͔ͬͨ
SnapKit myView.snp_makeConstraints { (make) in make.left.equalTo(view) } » NSLayoutAnchor ʹ͍͚ۙͲɺΑΓγϯϓϧ
» ඇ Auto Layout Ͱ frame Λૢ࡞͢Δײ֮ʹҊ֎͍ۙ
Exapmle 1 : Basics myView.snp_makeConstraints { (make) in make.top.equalTo(view).offset(20) make.left.equalTo(view).offset(20)
make.bottom.equalTo(view).offset(-20) make.right.equalTo(view).offset(-20) } » top / left / bottom / right / width / height / centerX / centerY
More simplify myView.snp_makeConstraints { (make) in make.edges.equalTo(view).inset(UIEdgeInsetsMake(20, 20, 20, 20))
} » edges / size / center
Exapmle 2 : ViewAttribute subview1.snp_makeConstraints { (make) in make.top.equalTo(snp_topLayoutGuideBottom) make.left.right.equalTo(view)
make.height.equalTo(40) } subview2.snp_makeConstraints { (make) in make.top.equalTo(subview1.snp_bottom) make.left.right.equalTo(view) make.bottom.equalTo(snp_bottomLayoutGuideTop) }
Exapmle 3 : References var heightConstraint: Constraint! subview.snp_makeConstraints { (make)
in heightConstraint = make.height.equalTo(0).constraint } heightConstraint.updateOffset(60)
❤ SnapKit » Swift Ͱࣗવʹॻ͚Δ » Auto Layout ͷ੍ΛίʔυͰॻ͘ͷ͕ۤʹͳΒͳ͍ »
ʮͲ͏ॻ͔͘ʯͰͳ͘ʮͲΜͳ੍ΛΉ͔ʯͱ͍͏ϩδοΫʹूத Ͱ͖Δ
❤ SnapKit