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
510
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
6
ノートアプリにUndo機能を実装! UndoManager導入ポイント
watura
0
270
Swift Scripting入門
watura
0
120
2つのAuroraクラスタを同期したお話
watura
0
1.5k
Zaim API
watura
1
690
Featured
See All Featured
Building an army of robots
kneath
302
45k
A designer walks into a library…
pauljervisheath
205
24k
A better future with KSS
kneath
238
17k
Optimising Largest Contentful Paint
csswizardry
33
3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Faster Mobile Websites
deanohume
305
30k
Producing Creativity
orderedlist
PRO
343
39k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
52k
Become a Pro
speakerdeck
PRO
26
5.1k
Six Lessons from altMBA
skipperchong
27
3.6k
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