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
1k
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
7
ノートアプリにUndo機能を実装! UndoManager導入ポイント
watura
0
410
Swift Scripting入門
watura
0
120
2つのAuroraクラスタを同期したお話
watura
0
1.6k
Zaim API
watura
1
710
Featured
See All Featured
Become a Pro
speakerdeck
PRO
28
5.4k
The World Runs on Bad Software
bkeepers
PRO
69
11k
Site-Speed That Sticks
csswizardry
10
650
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
790
Into the Great Unknown - MozCon
thekraken
39
1.9k
Facilitating Awesome Meetings
lara
54
6.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Building Applications with DynamoDB
mza
95
6.5k
Writing Fast Ruby
sferik
628
61k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
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