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
560
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
280
Swift Scripting入門
watura
0
120
2つのAuroraクラスタを同期したお話
watura
0
1.6k
Zaim API
watura
1
700
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Music & Morning Musume
bryan
46
6.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
29
4.6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
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