Slide 1

Slide 1 text

watura Ruby note Mobile Tech Talk #1

Slide 2

Slide 2 text

iOS AppΤϯδχΞ • noteʹೖͬͯ2೥൒ • ࠷ۙͷझຯʮͳΖ͏ʯখઆΛಡ Ή • ࿛͸຾Βͳ͍ • Ξζʔϧਤॻؗͷ࢘ॻ watura

Slide 3

Slide 3 text

Mobile Tech TalkͰRuby?

Slide 4

Slide 4 text

watura SwiftUIͰϧϏΛදࣔͯ͠Έͨ

Slide 5

Slide 5 text

໨࣍ • ϧϏΛ;Γ͍ͨ • UIViewControllerͰ;Δ • UIViewRepresentableͰ;Δ • CanvasͰඳը͢Δ • TextRendererͰ;Δ • ͦͷଞ • ·ͱΊ

Slide 6

Slide 6 text

|ϧϏʬ;Γ͕ͳʭΛ;Γ͍ͨ ϧϏͬͯRubyͬͯॻ͘ΜͩΑ noteͰ΋ϧϏ͸;Ε·͢ ΤσΟλͰೖྗதͱ͔ʹϧϏදࣔͰ͖Δͱ͍͍ΑͶʁ Ͱ΋ɺiOSΞϓϦͰϧϏͬͯεϜʔζʹ࢖͑ΔͷͩΖ͏͔ʁ

Slide 7

Slide 7 text

·ͱΊ • CoreText ͳΒͰ͖Δ • UIKitͰ΋;ΕΔ • ׬ᘳͱ͸ݴ͍͕͍ͨ • SwiftUIͷΈͰ;Γ͍ͨʁ • ͦΜͳػೳ͸ଘࡏ͠ͳ͍ • Text஍ࠈɾTextRenderer

Slide 8

Slide 8 text

4ͭͷํ๏ • UIViewControllerͰ;Δ • UIViewRepresentableͰ;Δ • CanvasͰඳը͢Δ • TextRendererͰ;Δ

Slide 9

Slide 9 text

UIViewControllerͰ;Δ UIViewControllerͱ͍͏͔CoreText CTRubyAnnotationCreateWithAttributes(_:_:_:_:_:) • දࣔ͢Δจࣈ • දࣔ͞ΕΔҐஔ΍දࣔํ๏ • ϕʔεͷจࣈ෯ʹ߹Θͤͯදࣔͱ͔ • ϧϏ͕௕͗͢Δͱ͖ͷॲཧํ๏ • ϧϏͷදࣔҐஔʢ্Լͱ͔ʣ

Slide 10

Slide 10 text

UIViewControllerͰ;Δ CTRubyAnnotationCreateWithAttributesΛNSAttributedStringͷ Attributeʹ͍ΕΔ͚ͩ

Slide 11

Slide 11 text

UIViewControllerͰ;Δ UITextViewͱ͔UILabelͰදࣔ͢Ε͹͍͍ΜͰ͠ΐʁ ߦؒͱ͔inset͕ਖ਼͘͠ࢦఆͰ͖͍ͯͳ͍

Slide 12

Slide 12 text

UIViewControllerͰ;Δ LineHeightMultipleͱ͔ContentInsetͱ͔ ϑΥϯταΠζʹΑͬͯม͑Δ

Slide 13

Slide 13 text

UIViewRepresentableͰ;Δ UIViewControllerͰ΍Δͷͱಉ͡ ௥ՃɿඳըαΠζʹ͋ΘͤͯεΫϩʔϧͱ͔ௐ੔ඞཁ

Slide 14

Slide 14 text

SwiftUI͡Όͳ͍Αʁ

Slide 15

Slide 15 text

CanvasͰඳը͢Δ ຊ໋ʁ ͢·͵ɻSwiftIU͡Όͳ͍ɻ SwiftUIͱ͍͏͔CoreGraphics CoreGraphics == kCTRubyAnnotationAttributeNa me ͕࢓ࣄΛ͢Δ

Slide 16

Slide 16 text

CanvasͰඳը͢Δ

Slide 17

Slide 17 text

CanvasͰඳը͢Δ • ࠲ඪܥͷҧ͍ • εΫϩʔϧ • ඳըྖҬͷαΠζ • CoreTextΛͦͷ··͔ͩΒʁ • ߦؒͱ͔ͷௐ੔ͳ͠Ͱ΋ΩϨΠ

Slide 18

Slide 18 text

࠲ඪܥͷҧ͍ ͻͬ͘Γฦͯ͠ɼཪฦ͢తͳ ಛੑ CoreGraphics (CG) UIKit ݪ఺ͷҐஔ ࠨԼ ࠨ্ Y࣠ͷ޲͖ Լ͔Β্΁ਖ਼ ্͔ΒԼ΁ਖ਼ X࣠ͷ޲͖ ࠨ͔Βӈ΁ਖ਼ ࠨ͔Βӈ΁ਖ਼ CoreGraphics (CG) UIKit

Slide 19

Slide 19 text

TextRendererͰ;Δ iOS 18Ҏ্ iOS18Ҏ্ʂʂ ͋ͱ2೥͘Β͍͸ϓϩμΫγϣϯͰ࢖͑ͳ͍ʁ

Slide 20

Slide 20 text

TextRendererͰ;Δ • SwiftUIͷTextΛඳը͢Δͱ͖ʹհೖͰ͖Δ • ΦϨΦϨϨϯμϦϯά͕Ͱ͖Δ • ଠࣈ • ৭ • എܠ৭ • ࠲ඪ • Ξχϝʔγϣϯ खಈͰϧϏඳըͪ͠Ό͑͹͍͍Μͩʂʂ

Slide 21

Slide 21 text

ྗਚ͖ͨͷͰΞυϕϯτΧϨϯ μʔͰهࣄʹ͢Δʂʂ

Slide 22

Slide 22 text

Canvasͱಉ͡Α͏ͳ໰୊͸΍ͬ ͺΓൃੜ͠·͢

Slide 23

Slide 23 text

ͦͷଞ • খ͞ͳϑΥϯταΠζͷ TextͱຊจTextΛVStackʹ ͢Ε͹ʂʂʂ • ҙ֎ͱಈ͖·͢ • ϑϧSwiftUI

Slide 24

Slide 24 text

ؾ߹͍ͷText஍ࠈ • TextͷαΠζΛܭࢉ • ಉ͡ߦʹೖΔͳΒHStackʹ͍ΕΔ • ೖΒͳ͍ͳΒɺ৽͍͠HStackʹ͍ΕΔ • ϧϏͳͱ͖͸̎ஈʹͨ͠ViewΛHStackʹ͍Ε Δ ͱ͍͏ྲྀΕ • ࡉ͔͍ϨϕϧͰαΠζܭࢉ͕͍ΔͷͰॏ͍ • ͍͍͔Μ͡ʹͰ͖ͨΒɺ͋Γͳͷ͔΋஌Ε ͳ͍ ૑࡞ ͩΕ΋͕ Λ͸͡Ίɺ ͦ͏͘͞ ଓ ͭͮ ͚ΒΕΔΑ͏ʹ͢Δɻ

Slide 25

Slide 25 text

·ͱΊ • CoreTextͳΒͰ͖Δ • ॎॻ͖΋Ͱ͖ͨΓ͢Δ • UIKitͷੈքͳΒ;ΕΔ • ׬ᘳͱ͸ݴ͍͕͍ͨ • SwiftUIͷΈͰ;Γ͍ͨʁ • ͦΜͳػೳ͸ଘࡏ͠ͳ͍ • Text஍ࠈɾTextRenderer

Slide 26

Slide 26 text

• 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