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
770
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
580
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
140
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
300
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
450
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
710
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
640
UICollectionView Compositional Layout
usamik26
0
720
Coding Swift with Visual Studio Code and Docker
usamik26
0
480
Swift Extension for Visual Studio Code
usamik26
2
970
Other Decks in Programming
See All in Programming
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
260
Ruby on cygwin 2025-02
fd0
0
140
2,500万ユーザーを支えるSREチームの6年間のスクラムのカイゼン
honmarkhunt
6
5.1k
[Fin-JAWS 第38回 ~re:Invent 2024 金融re:Cap~]FaultInjectionServiceアップデート@pre:Invent2024
shintaro_fukatsu
0
400
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
4
370
ペアーズでの、Langfuseを中心とした評価ドリブンなリリースサイクルのご紹介
fukubaka0825
2
300
Honoをフロントエンドで使う 3つのやり方
yusukebe
4
2.1k
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
240
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
1
170
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
110
時計仕掛けのCompose
mkeeda
1
280
Spring gRPC について / About Spring gRPC
mackey0225
0
220
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Designing Experiences People Love
moore
139
23k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
For a Future-Friendly Web
brad_frost
176
9.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Embracing the Ebb and Flow
colly
84
4.6k
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