Upgrade to Pro — share decks privately, control downloads, hide ads and more …

フェンリルの SwiftUI の研修を覗いてみる / Fenrir SwiftUI Training

フェンリルの SwiftUI の研修を覗いてみる / Fenrir SwiftUI Training

Studio Rookery

October 18, 2024
Tweet

More Decks by Studio Rookery

Other Decks in Technology

Transcript

  1. struct SampleView: View { var body: some View { VStack

    { Text("ABC") .foregroundStyle(.blue) .font(.system(size: 14)) Text("DEF") .foregroundStyle(.blue) .font(.system(size: 14)) Text("GHI") .foregroundStyle(.blue) .font(.system(size: 14)) } } } 5FYU͕ͭ͋Δ
  2. struct SampleView: View { var body: some View { VStack

    { Text("ABC") .foregroundStyle(.blue) .font(.system(size: 14)) Text("DEF") .foregroundStyle(.blue) .font(.system(size: 14)) Text("GHI") .foregroundStyle(.blue) .font(.system(size: 14)) } } } ͦΕͧΕʹಉ͡૷০Λద༻͍ͯ͠Δ
  3. struct SampleView: View { var body: some View { VStack

    { Text("ABC") Text("DEF") Text("GHI") } .foregroundStyle(.blue) .font(.system(size: 14)) } } ಉ͡Ͱ͋Ε͹਌7JFXʹద༻͢Ε͹ͦͷࢠଙͷ7JFXશͯʹ఻೻͢Δ
  4. struct SampleView: View { var body: some View { VStack

    { Text("ABC") Text("DEF") Text("GHI") Text("JKL") .foregroundStyle(.red) } .foregroundStyle(.blue) .font(.system(size: 14)) } } Ұ෦Λม͍͑ͨ৔߹΋ͦͷ৔ॴʹ.PEJ fi FSΛ͚ͭΕ͹ྑ͍͚ͩ શͯͰ͸ͳ͍͕͜Ε͸CVUUPO4UZMF΍NJOJNVN4DBMF'VDUPSͳͲଞͷ.PEJ fi FS΋ಉ༷ ͜͜·Ͱ͸લఏ஌ࣝ ͜ΕΛԠ༻͢Δ
  5. ྫ͑͹σβΠϯࢦࣔͷจࣈ৭ͱσϑΥϧτͷจࣈ৭ͷ৭͕ࣅ͍ͯΔ৔߹ Α͘จࣈ৭Λઃఆ͠๨Εͯ͠·͍͕ͪ struct ContentView: View { var body: some View

    { VStack { Text("ઃఆࡁΈςΩετ") .foregroundStyle(Color.appText) Text("ઃఆ๨ΕςΩετ") //.foregroundStyle(Color.appText) } .font(.system(size: 25)) .bold() } }
  6. @main struct SwiftUI_TrainingApp: App { var body: some Scene {

    WindowGroup { ContentView() .foregroundStyle(.red) // ໨ཱͭ৭Λઃఆ } } } ϧʔτʹ͍ۙՕॴͰGPSFHSPVOE4UZMFΛద༻
  7. struct ContentView: View { var body: some View { Color.teal

    .frame(width: 100, height: 100) } } GSBNFΛ௥Ճ
  8. struct ContentView: View { var body: some View { Color.teal

    .frame(width: 100, height: 100) } } ʮαΠζΛࢦఆ͢Δʯͱ͍͏ ཧղ͸ݫີʹ͸ͪΐͬͱҧ͏
  9. struct SNSView: View { let posts = [ ... ]

    var body: some View { NavigationView { ScrollView { VStack(spacing: 0) { ForEach(posts) { post in HStack(alignment: .top) { Image(systemName: post.avatar) .resizable() .frame(width: 50, height: 50) .clipShape(Circle()) VStack(alignment: .leading) { HStack { Text(post.username) .font(.headline) Text(post.handle) .font(.subheadline) .foregroundColor(.gray) Spacer() Text(formatDate(post.time)) .font(.subheadline) .foregroundColor(.gray) } Text(post.content) .font(.body) if let imageName = post.image { Image(systemName: imageName) .resizable() .aspectRatio(contentMode: .fit) .frame(maxWidth: .infinity) ࣮श՝୊ͷྫϦϑΝΫλϦϯάνϟϨϯδ
  10. struct SNSView: View { let posts = [ ... ]

    var body: some View { NavigationView { ScrollView { VStack(spacing: 0) { ForEach(posts) { post in HStack(alignment: .top) { Image(systemName: post.avatar) .resizable() .frame(width: 50, height: 50) .clipShape(Circle()) VStack(alignment: .leading) { HStack { Text(post.username) .font(.headline) Text(post.handle) .font(.subheadline) .foregroundColor(.gray) Spacer() Text(formatDate(post.time)) .font(.subheadline) .foregroundColor(.gray) } Text(post.content) .font(.body) if let imageName = post.image { Image(systemName: imageName) .resizable() .aspectRatio(contentMode: .fit) .frame(maxWidth: .infinity) ࣮श՝୊ͷྫϦϑΝΫλϦϯάνϟϨϯδ ϋϦϘςͷ7JFXΛ༻ҙ
  11. struct SNSView: View { let posts = [ ... ]

    var body: some View { NavigationView { ScrollView { VStack(spacing: 0) { ForEach(posts) { post in HStack(alignment: .top) { Image(systemName: post.avatar) .resizable() .frame(width: 50, height: 50) .clipShape(Circle()) VStack(alignment: .leading) { HStack { Text(post.username) .font(.headline) Text(post.handle) .font(.subheadline) .foregroundColor(.gray) Spacer() Text(formatDate(post.time)) .font(.subheadline) .foregroundColor(.gray) } Text(post.content) .font(.body) if let imageName = post.image { Image(systemName: imageName) .resizable() .aspectRatio(contentMode: .fit) .frame(maxWidth: .infinity) ࣮श՝୊ͷྫϦϑΝΫλϦϯάνϟϨϯδ શͯͷϨΠΞ΢τΛΘ͟ͱCPEZʹू໿ େମߦ͙Β͍͋Δ
  12. import SwiftUI struct Post: Identifiable { let id = UUID()

    let username: String let handle: String let time: Date let content: String let avatar: String let retweets: Int let likes: Int let comments: Int let views: Int let image: String? } struct SNSView: View { let posts = [ Post( username: "John Doe", handle: "@johndoe", time: Date(), content: "μ΢ϯλ΢ϯͷ৽͍͠ΧϑΣͰ࠷ߴͷίʔώʔΛҿΈ·ͨ͠ʂ", avatar: "person.circle", retweets: 12, likes: 34, comments: 5, views: 120, image: nil ), Post( username: "Jane Smith", handle: "@janesmith", time: Date().addingTimeInterval(-3600), content: "࠷৽ͷιϑτ΢ΣΞΞοϓσʔτͷ৽ػೳ͕େ޷͖Ͱ͢ʂ", avatar: "person.circle.fill", retweets: 20, likes: 55, comments: 8, views: 200, image: nil ), Post( username: "Alice Johnson", handle: "@alicej", time: Date().addingTimeInterval(-7200), content: "ࠓ೔ͷϏʔνͰͷඒ͍͠༦೔ɻ", avatar: "person", retweets: 18, likes: 45, comments: 3, views: 180, image: "sun.max" ), Post( username: "Bob Brown", handle: "@bobb", time: Date().addingTimeInterval(-86400), content: "ࠓேͷૉ੖Β͍͠ϫʔΫΞ΢τηογϣϯɻ", avatar: "person.crop.circle", retweets: 10, likes: 30, comments: 2, views: 150, image: "figure.walk" ), Post( username: "Charlie Davis", handle: "@charlied", time: Date().addingTimeInterval(-172800), content: "ྺ࢙ʹؔ͢Δڵຯਂ͍ຊΛಡΜͰ͍·͢ɻ", avatar: "person.crop.circle.fill", retweets: 25, likes: 60, comments: 10, views: 220, image: nil ), Post( username: "Dana Lee", handle: "@danalee", time: Date().addingTimeInterval(-259200), content: "ࠓ೔͸͓͍͍͠ΫοΩʔΛম͖·ͨ͠ɻ", avatar: "person.circle", retweets: 15, likes: 50, comments: 6, views: 170, image: nil ), Post( username: "Evan Green", handle: "@evangreen", time: Date().addingTimeInterval(-345600), content: "ࢁͰϋΠΩϯάʹߦ͖·ͨ͠ɻͱͯ΋ϦϑϨογϡ͠·ͨ͠ʂ", avatar: "person.circle.fill", retweets: 22, likes: 58, comments: 9, views: 210, image: nil ), Post( username: "Fiona White", handle: "@fionawhite", time: Date().addingTimeInterval(-432000), content: "৽͍͠ςϨϏγϦʔζΛݟ͍ͯ·͢ɻຊ౰ʹ໘ന͍Ͱ͢ʂ", avatar: "person", retweets: 30, likes: 75, comments: 12, views: 240, image: nil ), Post( username: "George King", handle: "@georgek", time: Date().addingTimeInterval(-518400), content: "ࠓ໷ͷσΟφʔͷͨΊʹ৽͍͠ϨγϐΛࢼ͍ͯ͠·͢ɻ", avatar: "person.crop.circle", retweets: 14, likes: 40, comments: 4, views: 160, image: nil ), Post( username: "Hannah Scott", handle: "@hannahs", time: Date().addingTimeInterval(-604800), content: "ࠓ೔͸ത෺ؗΛ๚Ε·ͨ͠ɻͨ͘͞Μͷັྗతͳల͕ࣔ͋Γ·ͨ͠ɻ", avatar: "person.crop.circle.fill", retweets: 28, likes: 70, comments: 11, views: 230, image: "building.columns" ) ] var body: some View { NavigationView { ScrollView { VStack(spacing: 0) { ForEach(posts) { post in HStack(alignment: .top) { Image(systemName: post.avatar) .resizable() .frame(width: 50, height: 50) .clipShape(Circle()) VStack(alignment: .leading) { HStack { Text(post.username) .font(.headline) Text(post.handle) .font(.subheadline) .foregroundColor(.gray) Spacer() Text(formatDate(post.time)) .font(.subheadline) .foregroundColor(.gray) } Text(post.content) .font(.body) if let imageName = post.image { Image(systemName: imageName) .resizable() .aspectRatio(contentMode: .fit) .frame(maxWidth: .infinity) .padding(.horizontal) } HStack { Button { } label: { HStack { Image(systemName: "message") Text("\(post.comments)") } } Spacer() Button { } label: { HStack { Image(systemName: "arrow.2.squarepath") Text("\(post.retweets)") } } Spacer() Button { } label: { HStack { Image(systemName: "heart") Text("\(post.likes)") } } Spacer() HStack { Image(systemName: "eye") Text("\(post.views)") } } .foregroundColor(.gray) .padding([.horizontal, .bottom], 10) } } .padding([.horizontal, .top], 10) Divider() } } } .navigationBarTitle("ϗʔϜ", displayMode: .inline) .overlay { HStack { Spacer() VStack { Spacer() Button { } label: { Image(systemName: "plus") .resizable() .frame(width: 24, height: 24) .padding() .background(Color.blue) .foregroundColor(.white) .clipShape(Circle()) .shadow(radius: 10) } .padding() } } } } } func formatDate(_ date: Date) -> String { let formatter = RelativeDateTimeFormatter() formatter.unitsStyle = .short return formatter.localizedString(for: date, relativeTo: Date()) } } #Preview { SNSView() } શ෦ग़͢ͱ͜Μͳײ͡ ͜ΕΛෳ਺ͷ7JFX΍ϑΝΠϧʹ෼ׂͯ͠΋Β͏