Slide 1

Slide 1 text

SwiftUI ʹ͓͚Δ Color पΓͷ࿩ –– Color ͱ Gradient ͔ΒݟΔ SwiftUI ΁ͷۤ೰ –– YUMEMI.swift #4 ~Enjoy SwiftUI vol2~ @גࣜձࣾΏΊΈ SwiftUI ʹ͓͚Δ Color पΓͷ࿩ – Color ͱ Gradient ͔ΒݟΔ SwiftUI ΁ͷۤ೰ – / Understanding SwiftUI focused by Gradient color usages

Slide 2

Slide 2 text

ಥવͰ͕͢ɼ͜Ε͸ԿͰ͠ΐ͏͔ɻ গ͠Ҿ͖·͢Ͷˠ

Slide 3

Slide 3 text

ΓΜ͝Ͱ͢ɻAppleͰ͢ɻ ۮવʹ΋զʑ͸ Apple ͱ͍͏ձࣾͷ੡඼Λར༻ͯ͠࢓ࣄΛ͍ͯ͠·͢ɻ

Slide 4

Slide 4 text

Rubens & Brueghel, The Garden of Eden with the fall of man ਆ࿩ʹ΋༻͍ΒΕ·͕͢ɼ ͜ͷ੺͍Ռ࣮͸ʮ৭ʯΛ௨ͯ͡ಈ෺ͱίϛϡχέʔγϣϯΛߦ͍·͢ɻ৭֮ͷൃୡͰ͢Ͷɻ ࠓճ͸ͦΜͳ৭ʹ͍ͭͯͷ͓࿩Ͱ͢ɻ (҆৺͍ͯͩ͘͠͞ɼՊֶऀ͸͠͹͠͹খൌͱͯ͠ਆ࿩Λ༻͍·͢ɻ)

Slide 5

Slide 5 text

SwiftUI ʹ͓͚Δ Color पΓͷ࿩ YUMEMI.swift #4 ~Enjoy SwiftUI vol2~ @גࣜձࣾΏΊΈ –– Color ͱ Gradient ͔ΒݟΔ SwiftUI ΁ͷۤ೰ ––

Slide 6

Slide 6 text

͔ͨͶ •גࣜձࣾ VALU •ݸਓͰݚڀࢧԉ • ઐ໳͸ Learning & Behavior •try! Swift 2019 LT

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Environment-dependent color ͸ Overview ʹৄࡉ͕ॻ͔Ε͓ͯΓɼ

Slide 13

Slide 13 text

ͦΕ͸ `late-binding token` Ͱ͋Δ ͭ·Γɼ஗Ԇͯ͠ఆٛ͞ΕΔ΋ͷͰ͋Δ some View ͷ͜ͱͰ͢ɻ

Slide 14

Slide 14 text

࣮ࡍͷఆٛ͸ͪ͜Βˠ

Slide 15

Slide 15 text

୯ͳΔϋογϡ஋Λ࣋ͪ String ม׵Մೳͳ structͰ͢ɻ͔͠͠ˠ

Slide 16

Slide 16 text

extension ͱͯ͠ protocol View ʹద߹͍ͯ͠·͢ɻ

Slide 17

Slide 17 text

ॳظԽํ๏͸͍͔ͭ͋͘Γˠ

Slide 18

Slide 18 text

ಛ௃తͳ΋ͷ͸ - UIColor ͔ΒॳظԽͰ͖Δ - CGFloat Ͱ͸ͳ͘ (UIKit Ҏ֎Λར༻͢ΔͨΊ) Double ܕͰ3৭ࢦఆ͕ՄೳͰ͋Δɻ

Slide 19

Slide 19 text

͋Δ View ͷ υΩϡϝϯτ Ͱ͢ɻColor ʹؔ͢Δ 2ͭΛऔΓ্͛·͢ɻ

Slide 20

Slide 20 text

`forgroundColor` ͱ `backgound` ͷ 2ͭͷؔ਺Ͱ͢ɻ ຊ೔࿩͢಺༰͸ͪ͜ΒͰ͢ɻ

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

SwiftUI ʹ͸ `CAGradientLayer` Ͱ͔ͭͯදݱ͞Ε͍ͯͨΑ͏ʹɼ άϥσʔγϣϯ ͷ struct ΋༻ҙ͞Ε͓ͯΓˠ

Slide 26

Slide 26 text

`LinearGradient` ͳͲΛར༻ͯ͠഑৭ͷҐஔΛܾΊΔ͜ͱʹΑͬͯ View ͱͯ͠ར༻ՄೳʹͳΓ·͢ɻ ࣮ࡍʹݟͯΈ·͠ΐ͏ˠ

Slide 27

Slide 27 text

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

άϥσʔγϣϯ͞Εͨ `Text` ΛݟͯΈ·͠ΐ͏͔ˠ

Slide 31

Slide 31 text

ઌ΄Ͳఆٛͨ͠άϥσʔγϣϯΠϯελϯεΛ ྆ऀʹࢦఆ͠·͢........͕ˠ

Slide 32

Slide 32 text

͜ΕͰ͸μϝͳΜͰ͢ˠ

Slide 33

Slide 33 text

࣮ࡍʹ͸ίϯύΠϧΤϥʔͱͳΓ·͢ɻԿނͰ͠ΐ͏͔ˠ

Slide 34

Slide 34 text

άϥσʔγϣϯ͕ Color ʹద߹͍ͯ͠ͳ͍ͱౖΒΕ·ͨ͠ɻ ԿނͰ͠ΐ͏͔ɼάϥσʔγϣϯͷܕ͔Β֬ೝͯ͠Έ·͠ΐ͏ˠ

Slide 35

Slide 35 text

ShapeStyle ͱ View Ͱͨ͠ɻ Ͱ͸ ؔ਺ `foregroundColor()` ͸ͱ͍͏ͱˠ

Slide 36

Slide 36 text

Color ʹ͔͠։͔Ε͍ͯͳ͍͜ͱ͕ݪҼͰͨ͠ɻ Text ͷจࣈͦͷ΋ͷʹ͍ͭͯ͸ Color (͜͜Ͱ͸୯৭) ͷΈ͔͠ࢦఆͰ͖ͳ͍ͱ͍͏͜ͱʹͳΓ·͢ɻ

Slide 37

Slide 37 text

ؔ਺ `background()` ͸ some View ʹରͯ͠։͔Ε͍ͯ·͢ɻ ͜Ε͕ࣔ͢ͷ͸ˠ

Slide 38

Slide 38 text

Image ͷΑ͏ͳผͷ View Λഎܠʹࢦఆ͢Δ͜ͱ͕Ͱ͖Δͱ͍͏͜ͱͰ͢ɻ ͦΕͰ͸ɼ࣍ͷ View ͸Ͳ͏Ͱ͠ΐ͏͔ˠ

Slide 39

Slide 39 text

ͪΐͬͱݟʹ͍͘ͷͰ͕͢ɼ `Rectangle` Ͱ͢ɻ `Circle` ΍ `RoundedRectangle` ͳͲ΋͜Εͷ1ͭͰ͢ɻ ͜ͷڍಈΛ૝૾ͯ͠ཉ͍͠ͷͰ͕͢ˠ

Slide 40

Slide 40 text

`background` ʹ ੺ɼ `foregroundColor` ʹ ྘Λࢦఆ͍ͯ͠·͢ɻ ͜Ε͸Կ৭ʹͳΔͰ͠ΐ͏͔?

Slide 41

Slide 41 text

͜ͷ৔߹͸྘ͳΜͰ͢ɻ ద༻͞Εͨͷ͸ `foregroundColor` ɻ`background` Ͱ͸͋Γ·ͤΜɻ ͪͳΈʹ `background` ʹͷΈࢦఆͯ͠΋ˠ

Slide 42

Slide 42 text

͜ͷΑ͏ʹແࢹ͞Ε·͢ɻ (͜Ε͸ `background` Λࢦఆ͠ͳ͍৔߹ͱಉҰͰ͢)

Slide 43

Slide 43 text

·ͨɼ`foregroundColor` ʹࢦఆͨ͠··ผͷؔ਺ʹΑͬͯ ৭ΛมԽͤ͞Δ͜ͱ͕Ͱ͖·͢ˠ

Slide 44

Slide 44 text

`fill` Ͱ͢

Slide 45

Slide 45 text

(Rectangle ͸ Shape ͱݺ͹ΕΔ protocol ʹద߹͍ͯ͠·͕͢) `fill` ͸ ShapeStyle ΛҾ਺ʹऔΓ·͢ɻ

Slide 46

Slide 46 text

`ShapeStyle` ɻάϥσʔγϣϯʹ΋ద߹͍ͯ͠·͢Ͷɻ

Slide 47

Slide 47 text

`fill` ʹ͸ άϥσʔγϣϯΛར༻͢Δ͜ͱ͕Ͱ͖·ͨ͠ɻ

Slide 48

Slide 48 text

Summary • View •background(View) / foregroundColor(Color) • / ??? (View) • Shape •foregroundColor(Color) •fill(ShapeStyle) ^ ఻͍͑ͨ͜ͱ͸ 3఺ɼ1఺໨͸ ܕʹΑ੍ͬͯݶ͞ΕΔؔ਺͕͋Δͱ͍͏͜ͱɼ 2఺໨ɼෳ਺ͷ࣮૷ํ๏͕͋Δͱ͍͏͜ͱɻ ͦͯ͠3఺໨ɼView protocol ΁ͷద߹ʹΑ࣮ͬͯ૷ՄೳͰ͋Δؔ਺ʹ͸ɼ Ұ෦ͦͷ௨Γʹಈ͔ͳ͍΋ͷ͕͋Δͱ͍͏͜ͱɻ

Slide 49

Slide 49 text

Learn once, apply anywhere SwiftUI ͸ `Learn once, apply anywhere` Ͱ͋Δͱݴ͍·͢ɻ

Slide 50

Slide 50 text

Ͱ΋ͦͷ Once ͕طʹ ͭΒ͍Ͱ͢ΑͶɼ ҰํͰͦΜͳ͜ͱ͸ (Xcode 11.2 ͷෆ۩߹΋͋ΔͨΊ) Apple ΋ঝ஌ͷ͸ͣͰ͢ ͭΒ͍ͳΒͲ͏͢Δ͔ˠ

Slide 51

Slide 51 text

Apple ͸͖ͬͱ ։ൃऀ Λ΋ͬͱָʹ͠Α͏ͱվળ͢Δ͸ͣͰ͢ɻ Xcode 11 beta ͱ iOS 13 ͷසൟͳΞοϓσʔτͷ௨Γʹɻ

Slide 52

Slide 52 text

Learn once, apply anywhere `Learn once, apply anywhere` ͜Ε͸ؒҧ͍ˠ

Slide 53

Slide 53 text

Learn once, apply anywhere `Learn once, apply anywhere` ͜Ε͸ؒҧ͍ˠͩͱࢲ͸ࢥ͍·͢ˠ

Slide 54

Slide 54 text

Learn TWICE OR MORE, apply anywhere `Learn TWICE OR MORE, apply anywhere` ͕ਖ਼͍͠Ͱ͢Ͷɻ

Slide 55

Slide 55 text

ྑ͍ SwiftUI ϥΠϑΛ ......͓ͬͱͦ͏Ͱͨ͠ɼ `Text` ͷ άϥσʔγϣϯͰͨ͠Ͷɻ

Slide 56

Slide 56 text

ਖ਼ղ͸ ʮάϥσʔγϣϯΛ Base ͱͯ͠ `mask(View)` ʯͰ͢ɻ ͦΕͰ͸ɼྑ͍ SwiftUI ϥΠϑΛɻ

Slide 57

Slide 57 text

References • Color - SwiftUI | Apple Developer Documentation • foregroundColor(_:) - SwiftUI | Apple Developer Documentation • background(_:alignment:) - SwiftUI | Apple Developer Documentation • Gradient - SwiftUI | Apple Developer Documentation • LinearGradient - SwiftUI | Apple Developer Documentation • fill(_:style:) - SwiftUI | Apple Developer Documentation • Mac Catalyst - iOS - Human Interface Guidelines - Apple Developer • Cosmo/OpenSwiftUI - GitHub