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
840
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SnapKit
http://kanmoba.connpass.com/event/28416/
USAMI Kosuke
April 26, 2016
More Decks by USAMI Kosuke
See All by USAMI Kosuke
Onsager代数とその周辺 / Onsager algebra tsudoi
usamik26
0
710
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
270
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
400
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
560
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
830
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
740
UICollectionView Compositional Layout
usamik26
0
880
Coding Swift with Visual Studio Code and Docker
usamik26
0
590
Swift Extension for Visual Studio Code
usamik26
2
1.1k
Other Decks in Programming
See All in Programming
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
140
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
170
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
130
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
130
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
200
What's New in Android 2026
veronikapj
0
250
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
410
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
200
継続モナドとリアクティブプログラミング
yukikurage
3
680
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
830
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
380
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Building an army of robots
kneath
306
46k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Balancing Empowerment & Direction
lara
6
1.2k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Agile that works and the tools we love
rasmusluckow
331
22k
So, you think you're a good person
axbom
PRO
2
2.1k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
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