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
Ruby note Mobile Tech Talk #1
Search
watura
November 19, 2024
0
110
Ruby note Mobile Tech Talk #1
Ruby note Mobile Tech Talk #1
watura
November 19, 2024
Tweet
Share
More Decks by watura
See All by watura
iPhone が数秒おきにクラッシュするんだけど!
watura
0
4
ノートアプリにUndo機能を実装! UndoManager導入ポイント
watura
0
220
Swift Scripting入門
watura
0
110
2つのAuroraクラスタを同期したお話
watura
0
1.5k
Zaim API
watura
1
690
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
How to Ace a Technical Interview
jacobian
276
23k
Designing Experiences People Love
moore
138
23k
A Philosophy of Restraint
colly
203
16k
Unsuck your backbone
ammeep
668
57k
The Cult of Friendly URLs
andyhume
78
6k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Raft: Consensus for Rubyists
vanstee
136
6.6k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Transcript
watura Ruby note Mobile Tech Talk #1
iOS AppΤϯδχΞ • noteʹೖͬͯ2 • ࠷ۙͷझຯʮͳΖ͏ʯখઆΛಡ Ή • Βͳ͍ •
Ξζʔϧਤॻؗͷ࢘ॻ watura
Mobile Tech TalkͰRuby?
watura SwiftUIͰϧϏΛදࣔͯ͠Έͨ
࣍ • ϧϏΛ;Γ͍ͨ • UIViewControllerͰ;Δ • UIViewRepresentableͰ;Δ • CanvasͰඳը͢Δ •
TextRendererͰ;Δ • ͦͷଞ • ·ͱΊ
|ϧϏʬ;Γ͕ͳʭΛ;Γ͍ͨ ϧϏͬͯRubyͬͯॻ͘ΜͩΑ noteͰϧϏ;Ε·͢ ΤσΟλͰೖྗதͱ͔ʹϧϏදࣔͰ͖Δͱ͍͍ΑͶʁ ͰɺiOSΞϓϦͰϧϏͬͯεϜʔζʹ͑ΔͷͩΖ͏͔ʁ
·ͱΊ • CoreText ͳΒͰ͖Δ • UIKitͰ;ΕΔ • ᘳͱݴ͍͕͍ͨ • SwiftUIͷΈͰ;Γ͍ͨʁ
• ͦΜͳػೳଘࡏ͠ͳ͍ • TextࠈɾTextRenderer
4ͭͷํ๏ • UIViewControllerͰ;Δ • UIViewRepresentableͰ;Δ • CanvasͰඳը͢Δ • TextRendererͰ;Δ
UIViewControllerͰ;Δ UIViewControllerͱ͍͏͔CoreText CTRubyAnnotationCreateWithAttributes(_:_:_:_:_:) • දࣔ͢Δจࣈ • දࣔ͞ΕΔҐஔදࣔํ๏ • ϕʔεͷจࣈ෯ʹ߹Θͤͯදࣔͱ͔ •
ϧϏ͕͗͢Δͱ͖ͷॲཧํ๏ • ϧϏͷදࣔҐஔʢ্Լͱ͔ʣ
UIViewControllerͰ;Δ CTRubyAnnotationCreateWithAttributesΛNSAttributedStringͷ Attributeʹ͍ΕΔ͚ͩ
UIViewControllerͰ;Δ UITextViewͱ͔UILabelͰදࣔ͢Ε͍͍ΜͰ͠ΐʁ ߦؒͱ͔inset͕ਖ਼͘͠ࢦఆͰ͖͍ͯͳ͍
UIViewControllerͰ;Δ LineHeightMultipleͱ͔ContentInsetͱ͔ ϑΥϯταΠζʹΑͬͯม͑Δ
UIViewRepresentableͰ;Δ UIViewControllerͰΔͷͱಉ͡ ՃɿඳըαΠζʹ͋ΘͤͯεΫϩʔϧͱ͔ௐඞཁ
SwiftUI͡Όͳ͍Αʁ
CanvasͰඳը͢Δ ຊ໋ʁ ͢·͵ɻSwiftIU͡Όͳ͍ɻ SwiftUIͱ͍͏͔CoreGraphics CoreGraphics == kCTRubyAnnotationAttributeNa me ͕ࣄΛ͢Δ
CanvasͰඳը͢Δ
CanvasͰඳը͢Δ • ࠲ඪܥͷҧ͍ • εΫϩʔϧ • ඳըྖҬͷαΠζ • CoreTextΛͦͷ··͔ͩΒʁ •
ߦؒͱ͔ͷௐͳ͠ͰΩϨΠ
࠲ඪܥͷҧ͍ ͻͬ͘Γฦͯ͠ɼཪฦ͢తͳ ಛੑ CoreGraphics (CG) UIKit ݪͷҐஔ ࠨԼ ࠨ্ Y࣠ͷ͖
Լ͔Β্ਖ਼ ্͔ΒԼਖ਼ X࣠ͷ͖ ࠨ͔Βӈਖ਼ ࠨ͔Βӈਖ਼ CoreGraphics (CG) UIKit
TextRendererͰ;Δ iOS 18Ҏ্ iOS18Ҏ্ʂʂ ͋ͱ2͘Β͍ϓϩμΫγϣϯͰ͑ͳ͍ʁ
TextRendererͰ;Δ • SwiftUIͷTextΛඳը͢Δͱ͖ʹհೖͰ͖Δ • ΦϨΦϨϨϯμϦϯά͕Ͱ͖Δ • ଠࣈ • ৭ •
എܠ৭ • ࠲ඪ • Ξχϝʔγϣϯ खಈͰϧϏඳըͪ͠Ό͍͍͑Μͩʂʂ
ྗਚ͖ͨͷͰΞυϕϯτΧϨϯ μʔͰهࣄʹ͢Δʂʂ
Canvasͱಉ͡Α͏ͳͬ ͺΓൃੜ͠·͢
ͦͷଞ • খ͞ͳϑΥϯταΠζͷ TextͱຊจTextΛVStackʹ ͢Εʂʂʂ • ҙ֎ͱಈ͖·͢ • ϑϧSwiftUI
ؾ߹͍ͷTextࠈ • TextͷαΠζΛܭࢉ • ಉ͡ߦʹೖΔͳΒHStackʹ͍ΕΔ • ೖΒͳ͍ͳΒɺ৽͍͠HStackʹ͍ΕΔ • ϧϏͳͱ͖̎ஈʹͨ͠ViewΛHStackʹ͍Ε Δ
ͱ͍͏ྲྀΕ • ࡉ͔͍ϨϕϧͰαΠζܭࢉ͕͍ΔͷͰॏ͍ • ͍͍͔Μ͡ʹͰ͖ͨΒɺ͋Γͳͷ͔Ε ͳ͍ ࡞ ͩΕ͕ Λ͡Ίɺ ͦ͏͘͞ ଓ ͭͮ ͚ΒΕΔΑ͏ʹ͢Δɻ
·ͱΊ • CoreTextͳΒͰ͖Δ • ॎॻ͖Ͱ͖ͨΓ͢Δ • UIKitͷੈքͳΒ;ΕΔ • ᘳͱݴ͍͕͍ͨ •
SwiftUIͷΈͰ;Γ͍ͨʁ • ͦΜͳػೳଘࡏ͠ͳ͍ • TextࠈɾTextRenderer
• CTRubyAnnotationCreateWithAttributes(_:_:_:_:_:) • https://developer.apple.com/documentation/coretext/1642000- ctrubyannotationcreatewithattrib • Canvas • https://developer.apple.com/documentation/swiftui/canvas •
GraphicsContext • https://developer.apple.com/documentation/swiftui/graphicscontext • Core Graphics • https://developer.apple.com/documentation/coregraphics • TextRenderer • https://developer.apple.com/documentation/SwiftUI/TextRenderer • textRenderer(_:) • https://developer.apple.com/documentation/swiftui/view/textrenderer(_:) • αϯϓϧίʔυ • https://gist.github.com/watura/08b06ad ff d79cab32be76eb0804306c1